Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
- using System;
- using System.IO;
- using System.Linq;
- using System.Collections.Generic;
- namespace CSharp_Shell
- {
- public static class Program
- {
- public static void Main()
- {
- decimal totalMoney = 0m;
- while(true)
- {
- string input = Console.ReadLine().ToLower();
- if(input == "start")
- {
- break;
- }
- else
- {
- decimal money = decimal.Parse(input);
- if(money ==0.1m || money ==0.2m||money==0.5m||money==1m||money==2m)
- {
- totalMoney+=money;
- }
- else
- {
- Console.WriteLine($"Cannot accept {money}");
- }
- }
- }
- string product = Console.ReadLine().ToLower();
- while(true)
- {
- if(product=="end")
- {
- break;
- }
- if(product=="nuts")
- {
- if(totalMoney < 2)
- {
- Console.WriteLine("Sorry, not enough money");
- continue;
- }
- Console.WriteLine($"Purchased {product}");
- totalMoney-=2;
- }
- else if(product=="coke")
- {
- if(totalMoney<1)
- {
- Console.WriteLine("Sorry, not enough money");
- continue;
- }
- Console.WriteLine($"Purchased {product}");
- totalMoney-=1;
- }
- else
- {
- Console.WriteLine("Invalid product");
- }
- }
- Console.WriteLine($"Change: {totalMoney:f2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement