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