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