Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- double needMoney, money;
- cin >> needMoney >> money;
- //stop: money >= needMoney
- //continue: money < needMoney
- int countAllDays = 0;
- int countSpendDays = 0; //дни, в които харчим
- while (money < needMoney) {
- //извършва действия
- string action; //spend или save
- cin >> action;
- double moneyAction;
- cin >> moneyAction;
- countAllDays++; //дни, в които харчим и дни, в които песним
- if (action == "save") {
- money += moneyAction;
- countSpendDays = 0;
- }
- else if (action == "spend") {
- countSpendDays++;
- money -= moneyAction;
- if (money < 0) {
- money = 0;
- }
- }
- if (countSpendDays == 5) {
- cout << "You can't save the money." << endl;
- cout << countAllDays << endl;
- break;
- }
- }
- if (money >= needMoney) {
- cout << "You saved the money for " << countAllDays << " days." << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment