Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _07_Vending_Machine_DONE_
- {
- class Program
- {
- static void Main(string[] args)
- {
- string start = "";
- string end = "";
- double strToNumb = 0;
- double change = 0;
- double nutsPrice = 2.0;
- string nuts = "nuts";
- double waterPrice = 0.7;
- string water = "water";
- double crispsPrice = 1.5;
- string crisps = "crisps";
- double sodaPrice = 0.8;
- string soda = "soda";
- double cokePrice = 1.0;
- string coke = "coke";
- while ((start = Console.ReadLine()) != "Start")
- {
- strToNumb = double.Parse(start);
- if (strToNumb == 0.1 || strToNumb == 0.2 || strToNumb == 0.5 || strToNumb == 1 || strToNumb == 2)
- {
- change += strToNumb;
- }
- else
- {
- Console.WriteLine($"Cannot accept {strToNumb}");
- }
- }
- while ((end = Console.ReadLine()) != "End")
- {
- if (end == "Nuts" && change >= nutsPrice)
- {
- end = nuts;
- change -= nutsPrice;
- Console.WriteLine($"Purchased {end}");
- }
- else if (end == "Water" && change >= waterPrice)
- {
- end = water;
- change -= waterPrice;
- Console.WriteLine($"Purchased {end}");
- }
- else if (end == "Crisps" && change >= crispsPrice)
- {
- end = crisps;
- change -= crispsPrice;
- Console.WriteLine($"Purchased {end}");
- }
- else if (end == "Soda" && change >= sodaPrice)
- {
- end = soda;
- change -= sodaPrice;
- Console.WriteLine($"Purchased {end}");
- }
- else if (end == "Coke" && change >= cokePrice)
- {
- end = coke;
- change -= cokePrice;
- Console.WriteLine($"Purchased {end}");
- }
- else
- {
- Console.WriteLine("Invalid product");
- }
- }
- Console.WriteLine($"Change: {change:f2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement