Advertisement
radidim

vending_machine.cs (C# Shell App Paste)

May 4th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
  2. using System;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Collections.Generic;
  6.  
  7. namespace CSharp_Shell
  8. {
  9.  
  10.     public static class Program
  11.     {
  12.         public static void Main()
  13.         {
  14.          
  15.           decimal totalMoney = 0m;
  16.           while(true)
  17.           {
  18.               string input = Console.ReadLine().ToLower();
  19.               if(input == "start")
  20.               {
  21.                   break;
  22.               }
  23.               else
  24.               {
  25.                   decimal money = decimal.Parse(input);
  26.                   if(money ==0.1m || money ==0.2m||money==0.5m||money==1m||money==2m)
  27.                   {
  28.                         totalMoney+=money;
  29.                   }
  30.                   else
  31.                   {
  32.                       Console.WriteLine($"Cannot accept {money}");
  33.                   }
  34.                  
  35.               }
  36.              
  37.           }
  38.           string product = Console.ReadLine().ToLower();
  39.          
  40.           while(true)
  41.           {
  42.               if(product=="end")
  43.               {
  44.                   break;
  45.               }
  46.              
  47.               if(product=="nuts")
  48.               {
  49.                   if(totalMoney < 2)
  50.                   {
  51.                       Console.WriteLine("Sorry, not enough money");
  52.                       continue;
  53.                   }
  54.                   Console.WriteLine($"Purchased {product}");
  55.                   totalMoney-=2;
  56.               }
  57.               else if(product=="coke")
  58.               {
  59.                   if(totalMoney<1)
  60.                   {
  61.                       Console.WriteLine("Sorry, not enough money");
  62.                       continue;
  63.                   }
  64.                   Console.WriteLine($"Purchased {product}");
  65.                   totalMoney-=1;
  66.               }
  67.               else
  68.               {
  69.                   Console.WriteLine("Invalid product");
  70.               }
  71.        
  72.           }
  73.           Console.WriteLine($"Change: {totalMoney:f2}");
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement