Advertisement
Guest User

Untitled

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