Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <math.h>
- using namespace std;
- /*Джеси е решила да събира пари за екскурзия и иска от вас да ѝ помогнете да разбере дали ще успее да
- събере необходимата сума.Тя спестява или харчи част от парите си всеки ден.Ако иска да похарчи повече
- от наличните си пари, то тя ще похарчи колкото има и ще ѝ останат 0 лева.*/
- int main()
- {
- double neededMoney;
- double ownedMoney;
- cin >> neededMoney >> ownedMoney;
- int daysCounter = 0;
- int spentCounter = 0;
- while (ownedMoney < neededMoney && spentCounter < 5)
- {
- string command = "";
- double currentMoney = 0;
- cin >> command, currentMoney;
- if (command == "spend")
- {
- ownedMoney -= currentMoney;
- if (ownedMoney < 0)
- {
- ownedMoney = 0;
- }
- spentCounter++;
- }
- if (command == "save")
- {
- ownedMoney += currentMoney;
- spentCounter = 0;
- }
- daysCounter++;
- }
- if (ownedMoney >= neededMoney)
- {
- cout << "You saved the money for " << daysCounter << endl;
- }
- if (spentCounter == 5)
- {
- cout << "You can't saved the money." << endl;
- cout << daysCounter << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement