0
0
Cprogramming~15 mins

Arithmetic operators - Mini Project: Build & Apply

Choose your learning style9 modes available
Arithmetic Operators in C
📖 Scenario: You are helping a small shop calculate the total cost of items bought by a customer. Each item has a price, and the customer buys a certain quantity of each item.
🎯 Goal: Build a simple C program that calculates the total cost for each item using arithmetic operators and then sums all the costs to find the grand total.
📋 What You'll Learn
Create variables for item prices and quantities
Use arithmetic operators to calculate total cost per item
Sum all item totals to get the grand total
Print the grand total
💡 Why This Matters
🌍 Real World
Calculating costs and totals is common in shopping, billing, and budgeting applications.
💼 Career
Understanding arithmetic operators and printing output is essential for any programming job involving calculations.
Progress0 / 4 steps
1
Create variables for item prices and quantities
Create four variables in C: price1 with value 10, quantity1 with value 2, price2 with value 15, and quantity2 with value 3.
C
Need a hint?

Use int to declare integer variables and assign the exact values given.

2
Create variables for total cost per item
Create two variables in C: total1 and total2. Use the multiplication operator * to calculate total1 as price1 * quantity1 and total2 as price2 * quantity2.
C
Need a hint?

Use the * operator to multiply price and quantity for each item.

3
Calculate the grand total
Create a variable grand_total and use the addition operator + to sum total1 and total2.
C
Need a hint?

Use the + operator to add the two totals.

4
Print the grand total
Use printf to display the text "Grand total: " followed by the value of grand_total and a newline.
C
Need a hint?

Use printf("Grand total: %d\n", grand_total); to print the result.