Discount on Purchase: C Program

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

  1.    
  2. #include < stdio.h >  
  3.   
  4. int main()  
  5. {  
  6.     int qty, dis;  
  7.     float rate, total;  
  8.   
  9.     printf("Enter rate and quantity\n");  
  10.     scanf("%f %d", &rate, &qty);  
  11.   
  12.     if(qty > 999)  
  13.     {  
  14.         dis = (qty * rate) * 10 / 100;  
  15.     }  
  16.     else  
  17.     {  
  18.         dis = 0;  
  19.     }  
  20.   
  21.     total = (rate * qty) - dis;  
  22.   
  23.     printf("Total Paid is Rs %f\n", total);  
  24.   
  25.     return 0;  
  26. }  

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



YouTube Link: https://www.youtube.com/watch?v=Af34KD12V_Y [Watch the Video In Full Screen.]


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