snaptrap013

Untitled

Jun 23rd, 2021
688
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. #include<stdlib.h>
  4.  
  5.  
  6. int getinput();
  7. float calcDiscount(int utilities,float amountpay,int typebill);
  8. void calcTotalpaid(float amountpay ,float discount,float *totaldiscount, float *totalpaid);
  9. void display(float totalpaid);
  10.  
  11. int main()
  12. {
  13.     int counter=1;
  14.     float totalpaid;
  15.     while (counter!=0)
  16.     {
  17.         int typebill,utilities,internet;
  18.         float amountpay = 0,totaldiscount,discount;
  19.         typebill=getinput();
  20.  
  21.         if (typebill==1)
  22.         {
  23.             printf("Enter 1=TNB or 2=SYABAS : ");
  24.             scanf("%d",&utilities);
  25.         }
  26.         else if(typebill==2)
  27.         {
  28.             printf("Enter 1=DIGI 2=UNIFI or 3=MAXIS FIBRE:");
  29.             scanf("%d", &internet);
  30.         }
  31.  
  32.         fflush(stdin);
  33.         printf("\nEnter amount to pay : ");
  34.         scanf(" %f",&amountpay);
  35.  
  36.         discount= calcDiscount( utilities, amountpay, typebill);
  37.         calcTotalpaid(amountpay ,discount,&totaldiscount,&totalpaid);
  38.         printf("\nTotal after discount = RM%.2f",totaldiscount);
  39.         printf("\nContinue? 1=yes, 0=no: ");
  40.         scanf("%d", &counter);
  41.     }
  42.         display(totalpaid);
  43.  
  44.  
  45.  
  46. return 0;
  47. }
  48.  
  49. int getinput()
  50. {
  51.     int typebill;
  52.     printf("\nEnter bill type (1=utilities, 2=internet): ");
  53.     scanf("%d",&typebill);
  54.     return typebill;
  55. }
  56.  
  57. float calcDiscount(int utilities,float amountpay,int typebill)
  58. {
  59.  
  60.  
  61.     float discount;
  62.     int internet;
  63.  
  64.     if (typebill==1)
  65.     {
  66.         if (utilities==1)
  67.         {
  68.             discount=0.05;
  69.         }
  70.         else
  71.         {
  72.             discount=0.1;
  73.         }
  74.     }
  75.     else
  76.     {
  77.         if (typebill==2)
  78.         {
  79.             if (internet==1)
  80.             {
  81.                 discount=0.05;
  82.             }
  83.             else if (internet==2)
  84.             {
  85.                discount=0.05;
  86.             }
  87.             else
  88.             {
  89.                 discount=0.05;
  90.             }
  91.         }
  92.     }
  93.  return discount;
  94. }
  95.  
  96. void calcTotalpaid(float amountpay ,float discount,float *totaldiscount, float *totalpaid)
  97. {
  98.     *totaldiscount= amountpay*(1-discount);
  99.  
  100.     *totalpaid= *totalpaid + *totaldiscount;
  101. }
  102.  
  103. void display(float totalpaid)
  104. {
  105.     printf("\nTotal paid : RM %.2f", totalpaid);
  106.     printf("\nThank You for using TickNGo");
  107. }
RAW Paste Data