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.
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;
}
If you have any confusion regarding the program, please, comment below.
Happy Coding ! Stay Safe ! Stafy Positive !
Thank you.
0 comments:
Post a Comment