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