Advertisement
alexbancheva

Trip Expenses

Nov 28th, 2019
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.79 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Trip_Expenses
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int countOfDaysOff = int.Parse(Console.ReadLine());
  10.             int limitPerDay = 60;
  11.             string command = string.Empty;
  12.             int counterProduct = 0;
  13.             int moneyLeft = 0;
  14.             int sumSpend = 0;
  15.            
  16.             bool hasSpend = false;
  17.             bool hasDayOff = false;
  18.  
  19.  
  20.             for (int i = 1; i <= countOfDaysOff; i++)
  21.             {
  22.                 while (true)
  23.                 {
  24.                     command = Console.ReadLine();
  25.                     counterProduct++;
  26.  
  27.                     if (command != "Day over")
  28.                     {
  29.                         if (int.Parse(command) >= limitPerDay)
  30.                         {
  31.                             counterProduct = 0;
  32.                             continue;
  33.                         }
  34.                         else
  35.                         {
  36.                             sumSpend += int.Parse(command);
  37.  
  38.                             if (sumSpend >= limitPerDay)
  39.                             {
  40.                              
  41.                                 hasSpend = true;
  42.                                 break;
  43.                             }
  44.                             //else
  45.                             //{
  46.                             //    moneyLeft = limitPerDay - sumSpend;
  47.                             //}
  48.                         }
  49.                     }
  50.                     else if (command == "Day over") //|| (limitPerDay > sumSpend))
  51.                     {
  52.                        
  53.                         // limitPerDay += moneyLeft;
  54.                        counterProduct -= 1;
  55.                         hasDayOff = true;
  56.                         break;
  57.                     }
  58.                    
  59.                 }
  60.                
  61.              
  62.  
  63.                 if (hasSpend == true)
  64.                 {
  65.                     Console.WriteLine($"Daily limit exceeded! You've bought {counterProduct} products.");
  66.                     //counterProduct = 0;
  67.                     //sumSpend = 0;
  68.                 }
  69.                 else if (hasDayOff == true)
  70.                 {
  71.  
  72.                     moneyLeft = limitPerDay - sumSpend;
  73.                     Console.WriteLine($"Money left from today: {moneyLeft}. You've bought {counterProduct} products.");
  74.                      
  75.                 }
  76.                
  77.                 counterProduct = 0;
  78.                 sumSpend = 0;
  79.  
  80.                 //moneyLeft = limitPerDay - sumSpend;
  81.                 //limitPerDay += moneyLeft;
  82.  
  83.                 counterProduct = 0;
  84.                
  85.  
  86.             }
  87.             moneyLeft = limitPerDay - sumSpend;
  88.             limitPerDay += moneyLeft;
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement