Advertisement
Nephelir

Vacantion

Feb 12th, 2020
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. /*Джеси е решила да събира пари за екскурзия и иска от вас да ѝ помогнете да разбере дали ще успее да
  9. събере необходимата сума.Тя спестява или харчи част от парите си всеки ден.Ако иска да похарчи повече
  10. от наличните си пари, то тя ще похарчи колкото има и ще ѝ останат 0 лева.*/
  11.  
  12.  
  13. int main()
  14. {
  15. double neededMoney;
  16. double ownedMoney;
  17.  
  18. cin >> neededMoney >> ownedMoney;
  19.  
  20. int daysCounter = 0;
  21. int spentCounter = 0;
  22.  
  23. while (ownedMoney < neededMoney && spentCounter < 5)
  24. {
  25. string command = "";
  26. double currentMoney = 0;
  27.  
  28. cin >> command, currentMoney;
  29.  
  30. if (command == "spend")
  31. {
  32. ownedMoney -= currentMoney;
  33.  
  34. if (ownedMoney < 0)
  35. {
  36. ownedMoney = 0;
  37. }
  38. spentCounter++;
  39. }
  40.  
  41. if (command == "save")
  42. {
  43. ownedMoney += currentMoney;
  44. spentCounter = 0;
  45. }
  46.  
  47.  
  48. daysCounter++;
  49.  
  50. }
  51.  
  52. if (ownedMoney >= neededMoney)
  53. {
  54. cout << "You saved the money for " << daysCounter << endl;
  55. }
  56.  
  57. if (spentCounter == 5)
  58. {
  59. cout << "You can't saved the money." << endl;
  60. cout << daysCounter << endl;
  61. }
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement