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 VendingMachine
- {
- class Program
- {
- static void Main()
- {
- decimal coinsTotal = 0m;
- while (true)
- {
- string start = Console.ReadLine().ToLower();
- if (start == "start")
- {
- break;
- }
- decimal coins = decimal.Parse(start);
- if (coins == 0.1m || coins == 0.2m || coins == 0.5m || coins == 1m || coins == 2m)
- {
- coinsTotal += coins;
- }
- else
- {
- Console.WriteLine($"Cannot accept {coins}");
- }
- }
- decimal nuts = 2.0m;
- decimal water = 0.7m;
- decimal crisps = 1.5m;
- decimal soda = 0.8m;
- decimal coke = 1.0m;
- while (true)
- {
- string product = Console.ReadLine().ToLower();
- if (product == "end")
- {
- break;
- }
- if (product == "nuts")
- {
- if (coinsTotal < nuts)
- {
- Console.WriteLine("Sorry, not enough money");
- }
- else
- {
- Console.WriteLine("Purchased nuts");
- coinsTotal = coinsTotal - nuts;
- }
- }
- else if (product == "water")
- {
- if (coinsTotal < water)
- {
- Console.WriteLine("Sorry, not enough money");
- }
- else
- {
- Console.WriteLine("Purchased water");
- coinsTotal = coinsTotal - water;
- }
- }
- else if (product == "crisps")
- {
- if (coinsTotal < crisps)
- {
- Console.WriteLine("Sorry, not enough money");
- }
- else
- {
- Console.WriteLine("Purchased crisps");
- coinsTotal = coinsTotal - crisps;
- }
- }
- else if (product == "soda")
- {
- if (coinsTotal < soda)
- {
- Console.WriteLine("Sorry, not enough money");
- }
- else
- {
- Console.WriteLine("Purchased soda");
- coinsTotal = coinsTotal - soda;
- }
- }
- else if (product == "coke")
- {
- if (coinsTotal < coke)
- {
- Console.WriteLine("Sorry, not enough money");
- }
- else
- {
- Console.WriteLine("Purchased coke");
- coinsTotal = coinsTotal - coke;
- }
- }
- else
- {
- Console.WriteLine("Invalid product");
- }
- }
- Console.WriteLine($"Change: {coinsTotal:f2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment