Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace VendingMachine
- {
- class Program
- {
- static void Main(string[] args)
- {
- double totalPrice = 0;
- string moneyInput = Console.ReadLine();
- while (moneyInput != "Start")
- {
- double moneyInputValue = double.Parse(moneyInput);
- if (moneyInput == "0,1" || moneyInput == "0,2" || moneyInput == "0,5" || moneyInput == "1" || moneyInput == "2")
- {
- totalPrice += moneyInputValue;
- }
- else
- {
- Console.WriteLine($"Cannot accept {moneyInputValue}");
- }
- moneyInput = Console.ReadLine();
- }
- string product = Console.ReadLine();
- double productPrice = 0;
- while (product != "End")
- {
- bool verify = false;
- string purchased = "";
- if (product == "Nuts")
- {
- productPrice = 2;
- purchased = "Purchased nuts";
- }
- else if (product == "Water")
- {
- productPrice = 0.7;
- purchased = "Purchased water";
- }
- else if (product == "Crisps")
- {
- productPrice = 1.5;
- purchased = "Purchased crisps";
- }
- else if (product == "Soda")
- {
- productPrice = 0.8;
- purchased = "Purchased soda";
- }
- else if (product == "Coke")
- {
- productPrice = 1;
- purchased = "Purchased coke";
- }
- else
- {
- Console.WriteLine("Invalid product");
- verify = true;
- product = Console.ReadLine();
- }
- if (verify == false)
- {
- if (totalPrice >= productPrice)
- {
- Console.WriteLine(purchased);
- totalPrice -= productPrice;
- product = Console.ReadLine();
- }
- else
- {
- Console.WriteLine("Sorry, not enough money");
- product = Console.ReadLine();
- }
- }
- }
- Console.WriteLine($"Change: {totalPrice:F2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement