Advertisement
Valantina

TripExpenses/Ex/27.07.2019

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