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