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