desislava_topuzakova

03. Vacation

Feb 7th, 2021
717
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     double needMoney, money;
  8.     cin >> needMoney >> money;
  9.  
  10.     //stop: money >= needMoney
  11.     //continue: money < needMoney
  12.     int countAllDays = 0;
  13.     int countSpendDays = 0; //дни, в които харчим
  14.     while (money < needMoney) {
  15.         //извършва действия
  16.         string action; //spend или save
  17.         cin >> action;
  18.         double moneyAction;
  19.         cin >> moneyAction;
  20.         countAllDays++; //дни, в които харчим и дни, в които песним
  21.         if (action == "save") {
  22.             money += moneyAction;
  23.             countSpendDays = 0;
  24.         }
  25.         else if (action == "spend") {
  26.             countSpendDays++;
  27.             money -= moneyAction;
  28.             if (money < 0) {
  29.                 money = 0;
  30.             }
  31.         }
  32.  
  33.         if (countSpendDays == 5) {
  34.             cout << "You can't save the money." << endl;
  35.             cout << countAllDays << endl;
  36.             break;
  37.         }
  38.  
  39.     }
  40.  
  41.     if (money >= needMoney) {
  42.         cout << "You saved the money for " << countAllDays << " days." << endl;
  43.     }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment