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