Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Excercises_VendingMachine
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- double sum = 0;
- while (input != "Start")
- {
- double coin = double.Parse(input);
- if (coin == 0.1 || coin == 0.2 || coin == 0.5 || coin == 1 || coin == 2)
- {
- sum = sum + coin;
- }
- else
- {
- Console.WriteLine($"Cannot accept {coin}");
- }
- input = Console.ReadLine();
- }
- string articul = Console.ReadLine();
- while (articul != "End")
- {
- if (articul == "Nuts")
- {
- double price = 2;
- if (sum - price >= 0)
- {
- Console.WriteLine($"Purchased nuts");
- sum = sum - price;
- }
- else
- {
- Console.WriteLine($"Sorry, not enough money");
- }
- }
- else if (articul == "Water")
- {
- double price = 0.7;
- if (sum - price >= 0)
- {
- Console.WriteLine($"Purchased water");
- sum = sum - price;
- }
- else
- {
- Console.WriteLine($"Sorry, not enough money");
- }
- }
- else if (articul == "Crisps")
- {
- double price = 1.5;
- if (sum - price >= 0)
- {
- Console.WriteLine($"Purchased crisps");
- sum = sum - price;
- }
- else
- {
- Console.WriteLine($"Sorry, not enough money");
- }
- }
- else if (articul == "Soda")
- {
- double price = 0.8;
- if (sum - price >= 0)
- {
- Console.WriteLine($"Purchased soda");
- sum = sum - price;
- }
- else
- {
- Console.WriteLine($"Sorry, not enough money");
- }
- }
- else if (articul == "Coke")
- {
- double price = 1;
- if (sum - price >= 0)
- {
- Console.WriteLine($"Purchased coke");
- sum = sum - price;
- }
- else
- {
- Console.WriteLine($"Sorry, not enough money");
- }
- }
- else
- {
- Console.WriteLine("Invalid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement