Advertisement
Guest User

AuthorSolution

a guest
Jun 24th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.83 KB | None | 0 0
  1. namespace tester1
  2. {
  3.     using System;
  4.  
  5.     public class StartUp
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             double budget = double.Parse(Console.ReadLine());
  10.  
  11.             int rejectionCount = 1;
  12.             string lastProduct = string.Empty;
  13.             double productPrice = 0;
  14.             bool areGood = true;
  15.  
  16.             while (true)
  17.             {
  18.                 string product = Console.ReadLine();
  19.                 if (product == "Going home.")
  20.                 {
  21.                     break;
  22.                 }
  23.                 productPrice = double.Parse(Console.ReadLine());
  24.                 if (productPrice > budget)
  25.                 {
  26.                     if (product == lastProduct)
  27.                     {
  28.                         rejectionCount++;
  29.                     }
  30.                     else
  31.                     {
  32.                         rejectionCount = 1;
  33.                     }
  34.                     Console.WriteLine($"You can't have {product} today!");
  35.                 }
  36.                 else
  37.                 {
  38.                     budget -= productPrice;
  39.                 }
  40.                 if (rejectionCount == 3)
  41.                 {
  42.                     Console.WriteLine("End of the walk!");
  43.                     areGood = false;
  44.                     break;
  45.                 }
  46.                 lastProduct = product;
  47.             }
  48.             if (areGood)
  49.             {
  50.                 Console.WriteLine("Good kids! We should go out more often!");
  51.                 Console.WriteLine($"Money left: {budget:F2}lv.");
  52.             }
  53.             else
  54.             {
  55.                 Console.WriteLine("Not so good kids! We are never going out again!");
  56.                 Console.WriteLine($"You have {budget:F2}lv and {lastProduct} costs {productPrice:F2}lv.");
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement