Advertisement
Stan0033

Untitled

Apr 16th, 2021
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. using System;
  2.  
  3. namespace vacation
  4. {
  5. class Program
  6. {
  7. static void Main()
  8. {
  9. double needed_money = double.Parse(Console.ReadLine());
  10. double Money_owned = double.Parse(Console.ReadLine());
  11. //------------------------------------
  12. int Days_In_Which_Money_Are_Spent = 0;
  13. int Days_Passed = 0;
  14. double Sum_Spent_For_5_days = 0;
  15. string action;
  16. double Sum_Spent_Or_Saved;
  17. bool isnull = false; ;
  18. double result;
  19. //------------------------------------
  20. while (true)
  21. {
  22. ++Days_Passed;
  23. //---------------------------------------------
  24. action = Console.ReadLine();
  25. string sum = Console.ReadLine();
  26.  
  27. isnull = double.TryParse(sum, out Sum_Spent_Or_Saved);
  28.  
  29. if (!isnull) { Sum_Spent_Or_Saved = Convert.ToDouble(sum); }
  30.  
  31. //---------------------------------------------
  32. if (action == "spend")
  33. {
  34. Sum_Spent_For_5_days += Sum_Spent_Or_Saved;
  35. ++Days_In_Which_Money_Are_Spent;
  36. Money_owned -= Sum_Spent_Or_Saved;
  37.  
  38. if (Days_In_Which_Money_Are_Spent == 5)
  39. { Console.WriteLine("You can't save the money."); Console.WriteLine(Days_Passed); break; }
  40. continue;
  41. }
  42.  
  43. if (action == "save") {
  44. Sum_Spent_For_5_days = 0;
  45. Days_In_Which_Money_Are_Spent = 0;
  46. Money_owned += Sum_Spent_Or_Saved;
  47. if (Money_owned >= needed_money) { Console.WriteLine($"You saved the money for {Days_Passed} days."); break; }
  48. }
  49.  
  50.  
  51.  
  52. }
  53.  
  54. }
  55. }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement