wigllytest

Untitled

Aug 10th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. double neededMoney, balance;
  8. cin >> neededMoney;
  9. cin >> balance;
  10.  
  11. int dayCounter = 0;
  12. int spendDayCount = 0;
  13.  
  14. while (balance < neededMoney)
  15. {
  16. string type;
  17. double money;
  18. cin >> type;
  19. cin >> money;
  20. dayCounter++;
  21.  
  22. if (type == "spend")
  23. {
  24. balance -= money;
  25. spendDayCount++;
  26. if (balance < 0)
  27. {
  28. balance = 0;
  29. }
  30. }
  31. else if (type == "save")
  32. {
  33. balance += money;
  34. spendDayCount = 0;
  35. }
  36.  
  37. if (spendDayCount == 5)
  38. {
  39. break;
  40. }
  41.  
  42. }
  43.  
  44. if (balance >= neededMoney)
  45. {
  46. cout << "You saved the money for " << dayCounter << " days.";
  47.  
  48. }
  49.  
  50. if (spendDayCount == 5)
  51. {
  52. cout << "You can't save the money." << endl;
  53. cout << dayCounter;
  54. }
  55.  
  56. return 0;
  57. }
Add Comment
Please, Sign In to add comment