Advertisement
veno0

Untitled

Oct 9th, 2019
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System;
  2. namespace ConditionalProject
  3. {
  4.     class Program
  5.     {
  6.         static void Main(string[] args)
  7.        {
  8.             double moneyNeededForTrip = double.Parse(Console.ReadLine());
  9.             double currentMoney = double.Parse(Console.ReadLine());
  10.            
  11.             int days = 0;
  12.            
  13.             while (true)
  14.             {
  15.                 string toDo = Console.ReadLine();
  16.                 double moneyToSpend = double.Parse(Console.ReadLine());
  17.                 days++;
  18.                 if(toDo == "save")
  19.                 {
  20.                     currentMoney = moneyToSpend + currentMoney;
  21.                    
  22.                 }
  23.                  else if (toDo == "spend" && currentMoney < moneyToSpend)
  24.                 {   //to do current money = -
  25.                     currentMoney = 0;
  26.                 }
  27.                 else
  28.                 {
  29.                     currentMoney = currentMoney - moneyToSpend;
  30.                 }  
  31.                 if(currentMoney < 0)
  32.                 {
  33.                     currentMoney = 0;
  34.                 }
  35.                 if(currentMoney >= moneyNeededForTrip)
  36.                 {
  37.                     Console.WriteLine($"You saved the money for {days} days.");
  38.                     break;
  39.                 }
  40.                 else if (days == 5 && toDo == "spend")
  41.                 {
  42.                     Console.WriteLine("You can't save the money.");
  43.                     Console.WriteLine($"{days}");
  44.                     break;
  45.                 }
  46.             }                  
  47.        }          
  48.         }
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement