Advertisement
Spocoman

03. Vacation

Sep 10th, 2023 (edited)
879
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     double moneyNeeded, budget, money;
  7.     cin >> moneyNeeded >> budget;
  8.  
  9.     int days = 0, spendDays = 0;
  10.  
  11.     string command;
  12.  
  13.     while (budget < moneyNeeded && spendDays < 5) {
  14.         cin >> command;
  15.         cin >> money;
  16.  
  17.         if (command == "spend") {
  18.             spendDays++;
  19.  
  20.             if (money >= budget) {
  21.                 budget = 0;
  22.             }
  23.             else {
  24.                 budget -= money;
  25.             }
  26.         }
  27.         else {
  28.             budget += money;
  29.             spendDays = 0;
  30.         }
  31.         days++;
  32.     }
  33.  
  34.     if (budget < moneyNeeded) {
  35.         cout << "You can't save the money.\n" << days << endl;
  36.     }
  37.     else {
  38.         cout << "You saved the money for " << days << " days." << endl;
  39.     }
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement