aggressiveviking

Untitled

Feb 24th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _06.TripExpenses
  4. {
  5.     class TripExpenses
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int daysOfTrip = int.Parse(Console.ReadLine());
  10.             double moneyLeft = 0.0;
  11.  
  12.             for (int i = 0; i < daysOfTrip; i++)
  13.             {
  14.                 double dayLimit = 60 + moneyLeft;
  15.  
  16.                 moneyLeft = 0;
  17.  
  18.                 string input = Console.ReadLine();
  19.  
  20.                 int products = 0;
  21.  
  22.                 while ("Day over" != input)
  23.                 {
  24.                     double price = double.Parse(input);
  25.  
  26.                     if (dayLimit - price >= 0)
  27.                     {
  28.                         dayLimit -= price;
  29.                         products++;
  30.                     }
  31.                     else
  32.                     {
  33.                         input = Console.ReadLine();
  34.                         continue;
  35.                     }
  36.  
  37.                     if (dayLimit == 0)
  38.                     {
  39.                         break;
  40.                     }
  41.  
  42.                     input = Console.ReadLine();
  43.                 }
  44.  
  45.                 if ("Day over" == input)
  46.                 {
  47.                     moneyLeft = Math.Abs(moneyLeft - dayLimit);
  48.                     Console.WriteLine($"Money left from today: {moneyLeft:F2}. You've bought {products} products.");
  49.                 }
  50.                 else
  51.                 {
  52.                     Console.WriteLine($"Daily limit exceeded! You've bought {products} products.");
  53.                 }
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment