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