Guest User

Vacation2

a guest
Aug 21st, 2019
108
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.  
  17.         cin>>action;
  18.         cin >> moneyVariable;
  19.         counterDays++;
  20.  
  21.         if(action=="spend"){
  22.  
  23.             moneyAvail=moneyAvail-moneyVariable;
  24.             counterSpend++;
  25.  
  26.             if(moneyAvail<0){
  27.                 moneyAvail=0;
  28.             }
  29.            
  30.  
  31.         } else if (action=="save"){
  32.             moneyAvail=moneyAvail+moneyVariable;
  33.             counterSpend=0;
  34.  
  35.         }
  36.        
  37.  
  38.     }
  39.  
  40.     if(moneyNeeded<=moneyAvail){
  41.     cout << "You saved the money for "<<counterDays<<" days."<< endl;
  42.     }
  43.     if(counterSpend>=5){
  44.         cout<<"You can't save the money."<<endl<<counterDays<<endl;
  45.  
  46.     }
  47.    
  48.  
  49. return 0;
  50. }
RAW Paste Data