Guest User

Vacation

a guest
Aug 21st, 2019
120
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
  15.     while (moneyNeeded>moneyAvail && counterSpend<5){
  16.         cin>>action;
  17.  
  18.         if(action=="spend"){
  19.             cin >> moneyVariable;
  20.             moneyAvail=moneyAvail-moneyVariable;
  21.             counterSpend++;
  22.  
  23.             if(moneyAvail<0){
  24.                 moneyAvail=0;
  25.             }
  26.  
  27.  
  28.         } else if (action=="save"){
  29.             cin >> moneyVariable;
  30.             moneyAvail=moneyAvail+moneyVariable;
  31.             counterSpend=0;
  32.             if(moneyAvail>=moneyNeeded){
  33.                 counterDays++;
  34.                 break;
  35.             }
  36.  
  37.         }
  38.         counterDays++;
  39.  
  40.     }
  41.  
  42.     if(moneyNeeded<=moneyAvail){
  43.     cout << "You saved the money for "<<counterDays<<" days."<< endl;
  44.     }
  45.     if(counterSpend==5){
  46.         cout<<"You can't save the money."<<endl<<counterDays<<endl;
  47.  
  48.             }
  49.  
  50. return 0;
  51. }
RAW Paste Data