Advertisement
Guest User

Untitled

a guest
Apr 13th, 2020
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1.  
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.      
  6. int main() {
  7.  
  8. std::cin.sync_with_stdio(false);
  9.     std::cout.sync_with_stdio(false);
  10.  
  11.     double needMoney;
  12.     double moneyAvail;
  13.     cin >> needMoney >> moneyAvail;
  14.     int counter = 0;
  15.     int spendCounter = 0;
  16.     int saveCounter = 0;
  17.     int money;
  18.     string command;
  19.  
  20.  
  21.     while((needMoney > moneyAvail) && (spendCounter < 5))
  22.     {
  23.         cin >> command;
  24.         cin >> money;
  25.         counter++;
  26.  
  27.  
  28.        
  29.         if(command == "save")
  30.         {
  31.             moneyAvail += money;
  32.             spendCounter = 0;
  33.             ;
  34.         }else if(command == "spend")
  35.         {
  36.               moneyAvail -= money;
  37.               spendCounter++;
  38.         }
  39.         // if(spendCounter == 5 && saveCounter == 0)
  40.         // {
  41.         //     cout << "You can't save the money. "  << endl;
  42.         //     cout << spendCounter << endl;
  43.         //     break;
  44.         // }
  45.         if(moneyAvail < 0)
  46.         {
  47.             moneyAvail = 0;
  48.         }
  49.     }
  50.  
  51.  
  52.    
  53.     if(spendCounter == 5)
  54.     {
  55.          cout << "You can't save the money. "  << endl;
  56.         cout << spendCounter << endl;
  57.     }
  58.    
  59.    if(needMoney <= moneyAvail )
  60.     {
  61.         cout << "You saved the money for " << counter << " days." << endl;
  62.     }
  63.    
  64.    
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement