mark79

Vacation

Aug 21st, 2019
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. main ()
  7. {
  8.     double moneyNeeded, moneyAvail, moneyVariable = 0;
  9.     cin >> moneyNeeded >> moneyAvail;
  10.  
  11.     int counterSpend = 0, counterDays = 0;
  12.     string action;
  13.  
  14.     while (moneyNeeded > moneyAvail && counterSpend < 5)
  15.     {
  16.         cin >> action;
  17.         cin >> moneyVariable;
  18.  
  19.         counterDays++;
  20.  
  21.         if( action == "spend" )
  22.         {
  23.             moneyAvail -= moneyVariable;
  24.             counterSpend++;
  25.  
  26.             if (moneyAvail < 0)
  27.             {
  28.                 moneyAvail = 0;
  29.             }
  30.         }
  31.         else if (action == "save")
  32.         {
  33.             moneyAvail += moneyVariable;
  34.             counterSpend = 0;
  35.         }
  36.     }
  37.  
  38.     if (moneyNeeded <= moneyAvail)
  39.     {
  40.         cout << "You saved the money for " << counterDays << " days." << endl;
  41.     }
  42.     if (counterSpend == 5)
  43.     {
  44.         cout << "You can't save the money." << endl << counterDays << endl;
  45.     }
  46.  
  47.     return 0;
  48. }
Add Comment
Please, Sign In to add comment