Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _07._Vending_Machine
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = "";
- string product = "";
- double coint = 0;
- double sum = 0;
- double sumProdicts = 0;
- while ((input=Console.ReadLine())!= "Start")
- {
- coint = double.Parse(input);
- switch (coint)
- {
- case 0.1:
- case 0.2:
- case 0.5:
- case 1:
- case 2:
- sum += coint;
- break;
- default:
- Console.WriteLine($"Cannot accept {coint}");
- break;
- }
- }
- const double Nuts = 2.0;
- const double Water = 0.7;
- const double Crisps = 1.5;
- const double Soda = 0.8;
- const double Coke = 1.0;
- while ((product=Console.ReadLine())!="End")
- {
- switch (product)
- {
- case "Nuts":
- if (sum < Nuts)
- {
- Console.WriteLine("Sorry, not enough money");
- break;
- }
- else
- {
- Console.WriteLine($"Purchased {product.ToLower()}");
- sum -= 2.0;
- }
- break;
- case "Water":
- if (sum < Water)
- {
- Console.WriteLine("Sorry, not enough money");
- break;
- }
- else
- {
- Console.WriteLine($"Purchased {product.ToLower()}");
- sum -= 0.7;
- }
- break;
- case "Crisps":
- if (sum < Crisps)
- {
- Console.WriteLine("Sorry, not enough money");
- break;
- }
- else
- {
- Console.WriteLine($"Purchased {product.ToLower()}");
- sum -= 1.5;
- }
- break;
- case "Soda":
- if (sum < Soda)
- {
- Console.WriteLine("Sorry, not enough money");
- break;
- }
- else
- {
- Console.WriteLine($"Purchased {product.ToLower()}");
- sum -= 0.8;
- }
- break;
- case "Coke":
- if (sum < Coke)
- {
- Console.WriteLine("Sorry, not enough money");
- break;
- }
- else
- {
- Console.WriteLine($"Purchased {product.ToLower()}");
- sum -= 1.0;
- }
- break;
- default:
- Console.WriteLine("Invalid product");
- break;
- }
- }
- Console.WriteLine($"Change: {sum:f2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment