Advertisement
Guest User

Vending machine

a guest
Sep 23rd, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.13 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Excercises_VendingMachine
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string input = Console.ReadLine();
  10.             double sum = 0;
  11.  
  12.             while (input != "Start")
  13.             {
  14.                 double coin = double.Parse(input);
  15.  
  16.                 if (coin == 0.1 || coin == 0.2 || coin == 0.5 || coin == 1 || coin == 2)
  17.                 {
  18.                     sum = sum + coin;
  19.                 }
  20.                 else
  21.                 {
  22.                     Console.WriteLine($"Cannot accept {coin}");
  23.                 }
  24.  
  25.                 input = Console.ReadLine();
  26.             }
  27.  
  28.            string articul = Console.ReadLine();
  29.  
  30.             while (articul != "End")
  31.             {
  32.                
  33.                 if (articul == "Nuts")
  34.                 {
  35.                     double price = 2;
  36.                     if (sum - price >= 0)
  37.                     {
  38.                         Console.WriteLine($"Purchased nuts");
  39.                         sum = sum - price;
  40.                     }
  41.                     else
  42.                     {
  43.                         Console.WriteLine($"Sorry, not enough money");
  44.                     }
  45.                 }
  46.                 else if (articul == "Water")
  47.                 {
  48.                     double price = 0.7;
  49.                     if (sum - price >= 0)
  50.                     {
  51.                         Console.WriteLine($"Purchased water");
  52.                         sum = sum - price;
  53.                     }
  54.                     else
  55.                     {
  56.                         Console.WriteLine($"Sorry, not enough money");
  57.                     }
  58.                 }
  59.                 else if (articul == "Crisps")
  60.                 {
  61.                     double price = 1.5;
  62.                     if (sum - price >= 0)
  63.                     {
  64.                         Console.WriteLine($"Purchased crisps");
  65.                         sum = sum - price;
  66.                     }
  67.                     else
  68.                     {
  69.                         Console.WriteLine($"Sorry, not enough money");
  70.                     }
  71.                 }
  72.                 else if (articul == "Soda")
  73.                 {
  74.                     double price = 0.8;
  75.                     if (sum - price >= 0)
  76.                     {
  77.                         Console.WriteLine($"Purchased soda");
  78.                         sum = sum - price;
  79.                     }
  80.                     else
  81.                     {
  82.                         Console.WriteLine($"Sorry, not enough money");
  83.                     }
  84.                 }
  85.                 else if (articul == "Coke")
  86.                 {
  87.                     double price = 1;
  88.                     if (sum - price >= 0)
  89.                     {
  90.                         Console.WriteLine($"Purchased coke");
  91.                         sum = sum - price;
  92.                     }
  93.                     else
  94.                     {
  95.                         Console.WriteLine($"Sorry, not enough money");
  96.                     }
  97.                 }
  98.                 else
  99.                 {
  100.                     Console.WriteLine("Invalid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement