Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConditionalProject
- {
- class Program
- {
- static void Main(string[] args)
- {
- double moneyNeededForTrip = double.Parse(Console.ReadLine());
- double currentMoney = double.Parse(Console.ReadLine());
- int days = 0;
- while (true)
- {
- string toDo = Console.ReadLine();
- double moneyToSpend = double.Parse(Console.ReadLine());
- days++;
- if(toDo == "save")
- {
- currentMoney = moneyToSpend + currentMoney;
- }
- else if (toDo == "spend" && currentMoney < moneyToSpend)
- { //to do current money = -
- currentMoney = 0;
- }
- else
- {
- currentMoney = currentMoney - moneyToSpend;
- }
- if(currentMoney < 0)
- {
- currentMoney = 0;
- }
- if(currentMoney >= moneyNeededForTrip)
- {
- Console.WriteLine($"You saved the money for {days} days.");
- break;
- }
- else if (days == 5 && toDo == "spend")
- {
- Console.WriteLine("You can't save the money.");
- Console.WriteLine($"{days}");
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement