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