Advertisement
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;
- namespace _07.Vending_Machine
- {
- class Program
- {
- static void Main(string[] args)
- {
- string comand;
- double money = 0;
- while (true)
- {
- comand = Console.ReadLine();
- if (comand == "Start")
- {
- break;
- }
- double coin = double.Parse(comand);
- if (coin == 0.1 || coin == 0.2 || coin == 0.5 || coin == 1 || coin == 2)
- {
- money += coin;
- }
- else
- {
- Console.WriteLine($"Cannot accept {coin}");
- }
- }
- while (true)
- {
- string drink = Console.ReadLine().ToLower();
- if (drink == "end")
- {
- Console.WriteLine($"Change: {money:F2}");
- break;
- }
- if (drink == "nuts")
- {
- if (money < 2)
- {
- Console.WriteLine("Sorry, not enough money");
- }
- else
- {
- money -= 2;
- Console.WriteLine("Purchased nuts");
- }
- }
- else if (drink == "water")
- {
- if (money < 0.7)
- {
- Console.WriteLine("Sorry, not enough money");
- }
- else
- {
- money -= 0.7;
- Console.WriteLine("Purchased water");
- }
- }
- else if (drink == "crisps")
- {
- if (money < 1.5)
- {
- Console.WriteLine("Sorry, not enough money");
- }
- else
- {
- money -= 1.5;
- Console.WriteLine("Purchased crisps");
- }
- }
- else if (drink == "soda")
- {
- if (money < 0.8)
- {
- Console.WriteLine("Sorry, not enough money");
- }
- else
- {
- money -= 0.8;
- Console.WriteLine("Purchased soda");
- }
- }
- else if (drink == "coke")
- {
- if (money < 1)
- {
- Console.WriteLine("Sorry, not enough money");
- }
- else
- {
- money -= 1.0;
- Console.WriteLine("Purchased coke");
- }
- }
- else
- {
- Console.WriteLine("Invalid product");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement