Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _7VendingMachine
- {
- class Program
- {
- static void Main(string[] args)
- {
- string money = Console.ReadLine();
- decimal totalSum = 0;
- while (money != "Start")
- {
- switch (money)
- {
- case "0.1":
- case "0.2":
- case "0.5":
- case "1":
- case "2":
- totalSum += decimal.Parse(money);
- break;
- default:
- Console.WriteLine($"Cannot accept {money}");
- break;
- }
- money = Console.ReadLine();
- }
- string product = Console.ReadLine();
- decimal productPrice = 0;
- while (product != "End")
- {
- switch (product)
- {
- case "Nuts":
- productPrice = 2.0m;
- break;
- case "Water":
- productPrice = 0.7m;
- break;
- case "Crisps":
- productPrice = 1.5m;
- break;
- case "Soda":
- productPrice = 0.8m;
- break;
- case "Coke":
- productPrice = 1.0m;
- break;
- default:
- Console.WriteLine("Invalid product");
- break;
- }
- if (totalSum >=productPrice && totalSum >0 && productPrice >0)
- {
- Console.WriteLine($"Purchased {product.ToLower()}");
- totalSum = totalSum - productPrice;
- productPrice = 0;
- }
- else if (productPrice >0)
- {
- Console.WriteLine("Sorry, not enough money");
- productPrice = 0;
- }
- product = Console.ReadLine();
- }
- Console.WriteLine($"Change: {totalSum:F2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement