Calculate Product Discount Price

Beginner

Introduction

In this challenge, you are tasked with creating a pricing calculation function for an online shopping platform. The goal is to develop a program that calculates discounted prices based on the original price and discount percentage.

The challenge requires you to implement a calculateDiscountedPrice function that takes the original price and discount percentage as input, calculates the final discounted price, and prints the original price, discount percentage, and discounted price.


Skills Graph

Calculate Product Discount Price

You are a junior developer tasked with creating a pricing calculation function for an online shopping platform. Your challenge is to develop a program that calculates discounted prices.

Tasks

  • Create a function calculateDiscountedPrice that takes the original price and discount percentage as input
  • Calculate the final price based on the original price and discount percentage

Requirements

  • Create the solution in the file ~/project/discountCalculator.go
  • Implement the calculateDiscountedPrice function with arithmetic operators
  • Round the final price to two decimal places
  • Handle discount percentages between 0 and 100

Examples

Example Input:

  • Original Price: $100.00
  • Discount Percentage: 20%
calculateDiscountedPrice(100.00, 20.00)
go run discountCalculator.go

Example Output:

Original Price: $100.00
Discount Percentage: 20%
Discounted Price: $80.00

Hints

  • Use arithmetic operators for calculations
  • Remember to convert percentage to a decimal (e.g., 20% = 0.2)
  • Use fmt.Printf() for formatted output with decimal places

Summary

In summary, this challenge requires you to develop a pricing calculation function for an online shopping platform. The goal is to create a program that calculates the discounted price based on the original price and discount percentage. You will need to implement the calculateDiscountedPrice function, which takes the original price and discount percentage as input, calculates the final discounted price, and prints the original price, discount percentage, and discounted price.