Advertisement
tsvetelinapasheva

VendingMachine

Mar 5th, 2021
88
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 StrongNumber
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string coins = Console.ReadLine();
  10.  
  11.             double totalMoneyInsert = 0;
  12.  
  13.  
  14.  
  15.             while (coins != "Start")
  16.             {
  17.                 double insertCoins = double.Parse(coins);
  18.                 if (insertCoins == 0.1 || insertCoins == 0.2 || insertCoins == 0.5 || insertCoins == 1 || insertCoins == 2)
  19.                 {
  20.                     totalMoneyInsert += insertCoins;
  21.                 }
  22.  
  23.                 else
  24.                 {
  25.                     Console.WriteLine($"Cannot accept {insertCoins}");
  26.                 }
  27.                 coins = Console.ReadLine();
  28.             }
  29.  
  30.             string product = Console.ReadLine();
  31.             double price = 0;
  32.  
  33.             while (product != "End")
  34.             {
  35.                 if (product == "Nuts")
  36.                 {
  37.                     price = 2.0;
  38.                 }
  39.                 else if (product == "Water")
  40.                 {
  41.                     price = 0.7;
  42.                 }
  43.                 else if (product == "Crisps")
  44.                 {
  45.                     price = 1.5;
  46.                 }
  47.                 else if (product == "Soda")
  48.                 {
  49.                     price = 0.8;
  50.                 }
  51.                 else if (product == "Coke")
  52.                 {
  53.                     price = 1.0;
  54.                 }
  55.                 else
  56.                 {
  57.                     Console.WriteLine("Invalid product");
  58.                 }
  59.  
  60.                 if (totalMoneyInsert < price)
  61.                 {
  62.                     totalMoneyInsert += price;
  63.                     Console.WriteLine("Sorry, not enough money");
  64.                 }
  65.                 else
  66.                 {
  67.                     Console.WriteLine($"Purchased {product.ToLower()}");
  68.                 }
  69.  
  70.                 totalMoneyInsert -= price;
  71.                 product = Console.ReadLine();
  72.             }
  73.  
  74.  
  75.             Console.WriteLine($"Change: {totalMoneyInsert:f2}");
  76.  
  77.         }
  78.     }
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement