0
0
Goprogramming~30 mins

Arithmetic operators in Go - Mini Project: Build & Apply

Choose your learning style9 modes available
Arithmetic Operators in Go
๐Ÿ“– Scenario: You are helping a small shop calculate the total cost of items bought by a customer. You will use arithmetic operators to add, subtract, multiply, and divide numbers.
๐ŸŽฏ Goal: Build a Go program that uses arithmetic operators to calculate the total price after applying a discount and tax.
๐Ÿ“‹ What You'll Learn
Create variables for item price and quantity
Create a variable for discount percentage
Calculate the total price before discount
Calculate the discount amount using arithmetic operators
Calculate the final price after discount and tax
Print the final price
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Calculating prices with discounts and taxes is common in shopping and billing systems.
๐Ÿ’ผ Career
Understanding arithmetic operators is essential for programming tasks involving calculations, finance, and data processing.
Progress0 / 4 steps
1
Create initial variables for price and quantity
Create two variables called price and quantity with values 50 and 3 respectively.
Go
Need a hint?

Use := to create variables and assign values in Go.

2
Add a discount percentage variable
Add a variable called discountPercent and set it to 10 to represent a 10% discount.
Go
Need a hint?

Remember to use := to declare and assign the variable.

3
Calculate total price and discount amount
Calculate the total price before discount as totalPrice by multiplying price and quantity. Then calculate the discount amount as discountAmount by multiplying totalPrice by discountPercent divided by 100.
Go
Need a hint?

Use * for multiplication and / for division.

4
Calculate final price and print it
Calculate the final price as finalPrice by subtracting discountAmount from totalPrice and then adding 5% tax. Print the finalPrice using fmt.Println.
Go
Need a hint?

Calculate tax as 5% of the discounted price and add it. Use fmt.Println to show the result.