Advertisement
snaptrap013

asdasd

May 2nd, 2021
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void Display_Menu();
  5. float Calculate_totalPayment();
  6. float Calculate_balance(float balance, float total);
  7. void Display_Receipt(float total, float balance);
  8.  
  9.  
  10. int main()
  11. {
  12.     char order = 'y';
  13.     float balance, total;
  14.     printf("Please enter your amount of topup: ");
  15.     scanf("%f", &balance);
  16.     Display_Menu();
  17.     while (order == 'y')
  18.     {
  19.         total = Calculate_totalPayment();
  20.         balance = Calculate_balance(balance, total);
  21.         Display_Receipt(total, balance);
  22.         printf("\nDo you want to order a new one [Y = yes | N = no]? ");
  23.         scanf(" %c", &order);
  24.     }
  25. }
  26.  
  27. void Display_Menu()
  28. {
  29.     printf("\nmenu : \nNasi Goreng RM5.00\nMee Goreng RM3.00\nTeh O RM1.00\nMilo Ice RM3.00");
  30. }
  31.  
  32. float Calculate_totalPayment()
  33. {
  34.     char food[256], drink[256];
  35.     int foodquantity, drinkquantity;
  36.     float foodPrice, drinkprice, total;
  37.     printf("\n\nPlease enter your food:");
  38.     fflush(stdin);
  39.     gets(food);
  40.     printf("Please enter your food quantity: ");
  41.     scanf(" %d", &foodquantity);  
  42.     printf("Please enter your drink:");
  43.     fflush(stdin);
  44.     gets(drink);
  45.     printf("Please enter your drink quantity: ");
  46.     scanf(" %d", &drinkquantity);
  47.     if(strcmp(food, "Nasi Goreng") == 0)
  48.         foodPrice = 5;
  49.     else
  50.         foodPrice = 3;
  51.     if(strcmp(drink, "Teh O") == 0)
  52.         drinkprice = 1;
  53.     else
  54.         drinkprice = 2;
  55.     total = (foodPrice * foodquantity ) + (drinkprice * drinkquantity);
  56.     return total;
  57. }
  58.  
  59. float Calculate_balance(float balance, float total)
  60. {
  61.     balance = balance - total;
  62.     return balance;
  63. }
  64.  
  65. void Display_Receipt(float total, float balance)
  66. {
  67.     printf("Total: %.2f\nBalance: %.2f", total, balance);
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement