amlxv

entry

Nov 28th, 2019 (edited)
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. double price(char, int);
  7. double discount(char, double);
  8.  
  9. int main()
  10. {
  11.     char category, stopResult;
  12.     int quantity, counter = 0;
  13.     double totalPrice, afterDisc = 0;
  14.     bool stop = false;
  15.  
  16.     while(stop == false){
  17.  
  18.     cout << "Enter the category : ";
  19.     cin >> category;
  20.     cout << "Enter the quantity : ";
  21.     cin >> quantity;
  22.  
  23.     counter += quantity;
  24.     totalPrice = price(category, quantity);
  25.     afterDisc += discount(category, totalPrice);
  26.  
  27.     cout << "Do you want to stop and print the receipt (Y/N) : " ;
  28.     cin >> stopResult;
  29.     cout << "\n";
  30.  
  31.     if (stopResult == 'Y')
  32.         stop = true;
  33.     else
  34.         stop = false;
  35.  
  36.     }
  37.  
  38.     cout.setf(ios::fixed);
  39.     cout.precision(2);
  40.     cout << "**************     RECEIPT     **************" << endl;
  41.     cout << "Quantity                       Price "         << endl;
  42.     cout << "---------                      ---------"      << endl;
  43.     cout << counter << "                              RM " << afterDisc << endl;
  44.     cout << "\n\nThank you. Please come again."             << endl;
  45.     cout << "*********************************************" << endl;
  46.  
  47.     return 0;
  48. }
  49.  
  50. double price (char choice, int num){
  51.  
  52.     double totalPrice = 0;
  53.  
  54.     if(choice == 'C')
  55.     totalPrice = num * 45.00;
  56.     else if(choice == 'A')
  57.     totalPrice = num * 5.00;
  58.     return totalPrice;
  59.  
  60. }
  61.  
  62. double discount(char choice, double totalPrice){
  63.  
  64.     int quantity;
  65.     double priceDisc = 0;
  66.  
  67.     if(choice == 'C'){
  68.         quantity = totalPrice / 45.00;
  69.         priceDisc = quantity * (45.00 * 0.8);
  70.     } else if(choice == 'A'){
  71.         quantity = totalPrice / 5.00;
  72.         priceDisc = quantity * (5.00 * 0.95);
  73.     }
  74.  
  75.     return priceDisc;
  76.  
  77. }
Add Comment
Please, Sign In to add comment