tissiana

Мъка

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