Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _7.Vending_Machine
- {
- class Program
- {
- static void Main(string[] args)
- {
- string Coint = Console.ReadLine();
- double totalMoney = 0;
- double moneyProduct = 0;
- while (Coint != "Start")
- {
- if (Coint == "0.1" ||
- Coint == "0.2" ||
- Coint == "0.5" ||
- Coint == "1" ||
- Coint == "2")
- {
- totalMoney += double.Parse(Coint);
- }
- else
- {
- Console.WriteLine($"Cannot accept {Coint}");
- }
- Coint = Console.ReadLine();
- }
- string Product = Console.ReadLine();
- while (Product != "End")
- {
- switch (Product)
- {
- case "Nuts":
- moneyProduct = 2.0;
- break;
- case "Water":
- moneyProduct = 0.7;
- break;
- case "Crisps":
- moneyProduct = 1.5;
- break;
- case "Soda":
- moneyProduct = 0.8;
- break;
- case "Coke":
- moneyProduct = 1.0;
- break;
- default:
- Console.WriteLine("Invalid product");
- break;
- }
- if (totalMoney >= moneyProduct && moneyProduct>0)
- {
- Console.WriteLine($"Purchased {Product.ToLower()}");
- totalMoney -= moneyProduct;
- }
- else if (moneyProduct > 0)
- {
- Console.WriteLine("Sorry, not enough money");
- }
- moneyProduct = 0;
- Product = Console.ReadLine();
- }
- Console.WriteLine($"Change: {totalMoney:f2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment