In this c program, we ask the user to input the price of the item and number of items(quantity) purchased. If the quantity is greater than 999 then we’ll give 10% discount orelse there will be no discount.
Related Read:
if else statement in C
Basic Arithmetic Operations In C
Source Code: To Calculate Total Expense
- #include < stdio.h >
- int main()
- {
- int qty, dis;
- float rate, total;
- printf("Enter rate and quantity\n");
- scanf("%f %d", &rate, &qty);
- if(qty > 999)
- {
- dis = (qty * rate) * 10 / 100;
- }
- else
- {
- dis = 0;
- }
- total = (rate * qty) - dis;
- printf("Total Paid is Rs %f\n", total);
- return 0;
- }
Output 1:
Enter rate and quantity
2
1000
Total Paid is Rs 1800.000000
Output 2:
Enter rate and quantity
2
500
Total Paid is Rs 1000.000000
Here is user purchases more than 999 items(quantity) then we provide a discount of 10%. Its calculated on the total purchase amount – which is calculated by multiplying rate and total quantity.
Discount on Purchase: C Program
According to the program logic, if the user purchases quantity above 999, then he / she will get 10% discount orelse no discount on purchase.
For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert