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