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