Advertisement
Guest User

Untitled

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