Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cmath>
- using namespace std;
- int main()
- {
- double vacationMoney;
- cin >> vacationMoney;
- double ownedMoney;
- cin >> ownedMoney;
- int daysCounter = 0;
- int spentCounter = 0;
- while (ownedMoney < vacationMoney && spentCounter < 5)
- {
- string command;
- cin >> command;
- double currentMoney;
- cin >> currentMoney;
- if (command == "spend")
- {
- ownedMoney -= currentMoney;
- if (ownedMoney < 0)
- {
- ownedMoney = 0;
- }
- spentCounter++;
- }
- if (command == "save")
- {
- ownedMoney += currentMoney;
- spentCounter = 0;
- }
- daysCounter++;
- }
- if (ownedMoney >= vacationMoney)
- {
- cout << "You saved the money for " << daysCounter << " days." << endl;
- }
- if (spentCounter == 5)
- {
- cout << "You can't save the money." << endl;
- cout << daysCounter << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement