Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. double total_check(double total);
  5.  
  6. int main()
  7. {
  8.     //variables
  9.     int choice = 0;
  10.     int dollars = 0;
  11.     int quarters = 0;
  12.     int dimes = 0;
  13.     int nickels = 0;
  14.     double const dollar = 1.00;
  15.     double const quarter = 0.25;
  16.     double const dime = 0.10;
  17.     double const nickel = 0.05;
  18.     double const twinkie = 3.50;
  19.     double total = 0.00;
  20.     double change = 0.00;
  21.  
  22.     cout.setf(ios::fixed);
  23.     cout.setf(ios::showpoint);
  24.     cout.precision(2);
  25.  
  26.     //Welcome message. Asks user for input. (dollars, quarters, dimes, nickels.)
  27.     cout << "Hello, This is the Deep Fried Twinkie Machine. Deposit $3.50 for a Twinkie." << endl <<  "I accept dollars, quarters, qimesand nickels." << endl;
  28.  
  29.  
  30.     do {
  31.         // Menu
  32.         cout << "1) Dollars " << endl;
  33.         cout << "2) Quarters " << endl;
  34.         cout << "3) Dimes " << endl;
  35.         cout << "4) Nickels " << endl;
  36.         cin >> choice;
  37.  
  38.         //Add and display coins and amount of money given by the user
  39.         if (choice == 1) //Option for dollars
  40.         {
  41.             ++dollars;
  42.             total = (total + dollar);
  43.         }
  44.         else if (choice == 2) //Option for Quarters
  45.         {
  46.             ++quarters;
  47.             total = (total + quarter);
  48.         }
  49.         else if (choice == 3) //Option for Dimes
  50.         {
  51.             ++dimes;
  52.             total = (total + dime);
  53.         }
  54.         else if (choice == 4) //Option for Nickels
  55.         {
  56.             ++nickels;
  57.             total = (total + nickel);
  58.         }
  59.         else { //Displays error message for wrong input that isn't d/q/di/n
  60.             cout << "Error" << endl;
  61.         }
  62.  
  63.         //Display the change in coin amount and money
  64.         cout << "You have entered the following coins: " << endl << "Dollars:      " << dollars << endl;
  65.         cout << "Quarters:     " << quarters << endl << "Dimes:        " << dimes << endl << "Nickels:      " << nickels << endl;
  66.         cout << "Total:       $" << total << endl << endl;
  67.  
  68.         //Check change
  69.         change = total_check(total);
  70.  
  71.     } while (total <= twinkie); //Program terminates if option = 0
  72.  
  73.     return 0;
  74. }
  75.  
  76. double total_check(double total)
  77. {
  78.     double change = 0.00;
  79.     double const twinkie = 3.50;
  80.     int choice;
  81.     if (total >= twinkie) //Checks for input of $3.50
  82.     {
  83.         change = (total - twinkie);
  84.         //Gives change if > 3.50
  85.         cout << "\nYour change is: $" << change << endl << "Come back again soon!" << endl;
  86.     }
  87.     return(change);
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement