Bill calculation after discount and loyalty discount for regular customer [book solution]

Solution of Book: A Textbook of C Programming, Page :194, Q.No: 28 

Marked price of different items in a electronics shop are listed as follows:
Item                                MP (Rs.) per piece
Computer                        25,000|-
Printer                             8,000|-
Photo copy machine       5,00,000|-
Fax Machine                  18,000|-

The shop gives 10% discount in computer, 5% in printer, 8% in photo copy machine
and 12% in Fax machine to all customers. Again, the shop gives 1% extra discount
in each item to regular customers.

Write a program that reads number of computers (nc), number of printers(np), number
of photo copy machine (npc), number of FAX machine (nf) purchased by a customer and
also reads types of customer (i.e. regular or not) from user and then computes actual
amount to be paid by the customer.

==> What we have done on Solution ?
We have to use if, else statement here as per customer type (i.e. regular and not). 
We just calculate total bills of every item and give discount as per discount available on that particular item. 
We generate final bill by summing up all the items total amount after deducting discounts/
For regular customer, we give extra 1% discount on final bill.    
 
Let's directly jump in the coding: 
 
Code goes like this: 
 
#include<stdio.h>
int main(){
int ncom,np,npcm,nfm;
float discount,comTotal,prinTotal,pcmTotal,fmTotal,grandTotal,finalBill;
char c;
printf("Enter number of computer purchased                      : \t");
scanf("%d",&ncom);
printf("Enter number of printer purchased                       : \t");
scanf("%d",&np);
printf("Enter number of photo copy machine purchased            : \t");
scanf("%d",&npcm);
printf("Enter a number of fax machine purchased                 : \t");
scanf("%d",&nfm);
printf("Enter a type of customer \n \t(r-regular, any key-not regular \t \t: \t");
scanf(" %c",&c);
comTotal=(ncom*25000)-((ncom*25000)*10)/100;                 //25000-2500=22500
prinTotal=(np*8000)-((np*8000)*5)/100;                       //8000-400= 7600
pcmTotal=npcm*500000-((npcm*500000)*8)/100;                  //500000-40000=460000
fmTotal=(nfm*18000)-((nfm*18000)*12)/100;                   //18000-2160=15840
grandTotal=(comTotal+prinTotal+pcmTotal+fmTotal);             //505940
if(c=='r'||c=='R'){
    finalBill=grandTotal-((grandTotal*1)/100);
    printf("\tYou are regular customer\n \t");
    printf("Your final bill after loyalty discount is \t: \t %.2f Nrs",finalBill);
}
else{
    finalBill=grandTotal;
    printf("\n \t Your final bill is : \t \t %.2f Nrs",finalBill);
}
return 0;
}
 
Output:  regular customer


 Output: Normal Customer
 

 
P.S: We have used Code Blocks IDE for coding & compilation of this program. 

 
If you have any confusion regarding the program, please, comment below.
Happy Coding ! Stay Safe ! Stafy Positive !
Thank you.

 

 

 


Share on Google Plus

About Nepali Xoro

Interested in Information Technology, Spreading Knowledge for Nepalease IT Students."Loves Traveling", Listen Music and Surfing web.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment