using System.Collections.Generic;
List<Dictionary<string, object>> products = new List<Dictionary<string, object>>
new Dictionary<string, object> {{"item", "1"}, {"name", "Coca Cola"}, {"price", 1.50}, {"stock", 3}},
new Dictionary<string, object> {{"item", "2"}, {"name", "Chips"}, {"price", 1.00}, {"stock", 0}},
new Dictionary<string, object> {{"item", "3"}, {"name", "Chocolate Milk"}, {"price", 0.75}, {"stock", 5}},
new Dictionary<string, object> {{"item", "4"}, {"name", "Water"}, {"price", 1.25}, {"stock", 10}},
new Dictionary<string, object> {{"item", "5"}, {"name", "Pepsi"}, {"price", 1.75}, {"stock", 15}},
new Dictionary<string, object> {{"item", "6"}, {"name", "Pie"}, {"price", 1.50}, {"stock", 2}},
new Dictionary<string, object> {{"item", "7"}, {"name", "Sausage Roll"}, {"price", 2.00}, {"stock", 4}},
new Dictionary<string, object> {{"item", "8"}, {"name", "Juice"}, {"price", 0.50}, {"stock", 11}}
Console.WriteLine("Products:");
Console.WriteLine("-------------------");
foreach (var item in products)
Console.WriteLine($"{item["item"]}: {item["name"]} - ${item["price"]:0.00} (Stock: {item["stock"]})");
Console.Write("Enter the currency amount: ");
double amount = double.Parse(Console.ReadLine());
Console.Write("Enter the product number: ");
string code = Console.ReadLine();
bool productFound = false;
foreach (var item in products)
if (item["item"].ToString() == code)
if ((int)item["stock"] > 0 && balance >= (double)item["price"])
item["stock"] = (int)item["stock"] - 1;
balance -= (double)item["price"];
Console.WriteLine($"You have purchased {item["name"]}");
Console.WriteLine($"Remaining balance: ${balance:0.00}");
else if ((int)item["stock"] == 0)
Console.WriteLine("Product out of stock.");
Console.WriteLine("Insufficient balance.");
Console.WriteLine("Not a product.");
Console.WriteLine($"Returned change: ${balance:0.00}");