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)
- {
- double money = 0;
- string coins = Console.ReadLine();
- while (coins != "Start")
- {
- if (coins != "0.1" && coins != "0.2" && coins != "0.5" && coins != "1" && coins != "2")
- {
- Console.WriteLine($"Cannot accept {coins}");
- }
- else
- {
- money += double.Parse(coins);
- }
- coins = Console.ReadLine();
- }
- string product = Console.ReadLine();
- double productPrice = 0;
- while (product != "End")
- {
- switch (product)
- {
- case "Nuts":
- productPrice = 2.0;
- break;
- case "Water":
- productPrice = 0.7;
- break;
- case "Crisps":
- productPrice = 1.5;
- break;
- case "Soda":
- productPrice = 0.8;
- break;
- case "Coke":
- productPrice = 1.0;
- break;
- default:
- Console.WriteLine("Invalid product");
- break;
- }
- if (money >= productPrice)
- {
- Console.WriteLine($"Purchased {product.ToLower()}");
- money = money - productPrice;
- productPrice = 0;
- }
- else
- {
- Console.WriteLine("Sorry, not enough money");
- productPrice = 0;
- }
- product = Console.ReadLine();
- }
- Console.WriteLine($"Change: {money:f2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement