Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.63 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp17
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.  
  10.  
  11.             double sum = 0;
  12.  
  13.             while (true)
  14.             {
  15.  
  16.                 string money = Console.ReadLine();
  17.  
  18.                 if (money == "Start")
  19.                 {
  20.                     break;
  21.                 }
  22.                 else if (money != "0.1" && money != "0.2" && money != "0.5" && money != "1" && money != "2")
  23.                 {
  24.                     Console.WriteLine($"Cannot accept {money}");
  25.  
  26.                 }
  27.                 else
  28.                 {
  29.                     sum += double.Parse(money);
  30.  
  31.                 }
  32.                
  33.             }
  34.            
  35.             while (true)
  36.             {
  37.  
  38.                 string product = Console.ReadLine();
  39.                
  40.                 if (product == "End")
  41.                 {
  42.                     break;
  43.                 }
  44.  
  45.                 else if (product != "Nuts" && product != "Water" && product != "Crisps" && product != "Soda" && product != "Coke")
  46.                 {
  47.                     Console.WriteLine("Invalid product");
  48.                 }
  49.  
  50.                 switch (product)
  51.                 {
  52.                     case "Nuts":
  53.                         if (sum < 2.0)
  54.                         {
  55.                             Console.WriteLine("Sorry, not enough money");
  56.                             break;
  57.                         }
  58.                         else
  59.                         {
  60.                             sum -= 2.0;
  61.                             Console.WriteLine($"Purchased nuts");
  62.                             break;
  63.                         }
  64.                     case "Water":
  65.                         if (sum < 0.7)
  66.                         {
  67.                             Console.WriteLine("Sorry, not enough money");
  68.                             break;
  69.                         }
  70.                         else
  71.                         {
  72.                             sum -= 0.7;
  73.                             Console.WriteLine($"Purchased water");
  74.                             break;
  75.                         }
  76.                     case "Crisps":
  77.                         if (sum < 1.5)
  78.                         {
  79.                             Console.WriteLine("Sorry, not enough money");
  80.                             break;
  81.                         }
  82.                         else
  83.                         {
  84.                             sum -= 1.5;
  85.                             Console.WriteLine($"Purchased crisps");
  86.                             break;
  87.                         }
  88.                     case "Soda":
  89.                         if (sum < 0.8)
  90.                         {
  91.                             Console.WriteLine("Sorry, not enough money");
  92.                             break;
  93.                         }
  94.                         else
  95.                         {
  96.                             sum -= 0.8;
  97.                             Console.WriteLine($"Purchased soda");
  98.                             break;
  99.                         }
  100.                     case "Coke":
  101.                         if (sum < 1.0)
  102.                         {
  103.                             Console.WriteLine("Sorry, not enough money");
  104.                             break;
  105.                         }
  106.                         else
  107.                         {
  108.                             sum -= 1.0;
  109.                             Console.WriteLine($"Purchased coke");
  110.                             break;
  111.                         }
  112.                 }
  113.                
  114.  
  115.             }
  116.  
  117.             Console.WriteLine($"Change: {sum:f2}");
  118.  
  119.  
  120.  
  121.         }
  122.  
  123.  
  124.     }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement