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