Advertisement
Daniel_007

04. Coffee Shop

Nov 2nd, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.07 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Exam
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int howManyAtStart = int.Parse(Console.ReadLine());
  10.             string cafe = "";
  11.             double money = 0;
  12.             while (true)
  13.             {
  14.                 if (howManyAtStart <= 0)
  15.                 {
  16.                     Console.WriteLine("No more coffee left!");
  17.                     break;
  18.                 }
  19.                 cafe = Console.ReadLine();
  20.                 if (cafe == "closed")
  21.                 {
  22.                     Console.WriteLine($"Coffee left: {howManyAtStart}g");
  23.                     break;
  24.                 }
  25.  
  26.                 switch (cafe)
  27.                 {
  28.                     case "espresso":
  29.                         if (howManyAtStart >= 50)
  30.                         {
  31.                             money += 3.00;
  32.                             howManyAtStart -= 50;
  33.                         }
  34.                         else
  35.                         {
  36.                             Console.WriteLine("Not enough coffee!");
  37.                         }
  38.  
  39.                         break;
  40.                     case "cappuccino":
  41.                         if (howManyAtStart >= 30)
  42.                         {
  43.                             money += 3.50;
  44.                             howManyAtStart -= 30;
  45.                         }
  46.                         else
  47.                         {
  48.                             Console.WriteLine("Not enough coffee!");
  49.                         }
  50.  
  51.                         break;
  52.  
  53.                     case "latte":
  54.                         if (howManyAtStart >= 20)
  55.                         {
  56.                             money += 3.50;
  57.                             howManyAtStart -= 20;
  58.                         }
  59.                         else
  60.                         {
  61.                             Console.WriteLine("Not enough coffee!");
  62.                         }
  63.  
  64.                         break;
  65.                 }
  66.  
  67.             }
  68.             Console.WriteLine($"Profit: {money:F2} lv.");
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement