Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace vacation
- {
- class Program
- {
- static void Main()
- {
- double needed_money = double.Parse(Console.ReadLine());
- double Money_owned = double.Parse(Console.ReadLine());
- //------------------------------------
- int Days_In_Which_Money_Are_Spent = 0;
- int Days_Passed = 0;
- double Sum_Spent_For_5_days = 0;
- string action;
- double Sum_Spent_Or_Saved;
- bool isnull = false; ;
- double result;
- //------------------------------------
- while (true)
- {
- ++Days_Passed;
- //---------------------------------------------
- action = Console.ReadLine();
- string sum = Console.ReadLine();
- isnull = double.TryParse(sum, out Sum_Spent_Or_Saved);
- if (!isnull) { Sum_Spent_Or_Saved = Convert.ToDouble(sum); }
- //---------------------------------------------
- if (action == "spend")
- {
- Sum_Spent_For_5_days += Sum_Spent_Or_Saved;
- ++Days_In_Which_Money_Are_Spent;
- Money_owned -= Sum_Spent_Or_Saved;
- if (Days_In_Which_Money_Are_Spent == 5)
- { Console.WriteLine("You can't save the money."); Console.WriteLine(Days_Passed); break; }
- continue;
- }
- if (action == "save") {
- Sum_Spent_For_5_days = 0;
- Days_In_Which_Money_Are_Spent = 0;
- Money_owned += Sum_Spent_Or_Saved;
- if (Money_owned >= needed_money) { Console.WriteLine($"You saved the money for {Days_Passed} days."); break; }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement