/// <summary> /// Moves to the purchase menu. /// </summary> /// <param name="balance"></param> public void PurchaseMenu(VendingMachine vendoMatic500) { Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("(1) Feed Money"); Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("(2) Select Product"); Console.ForegroundColor = ConsoleColor.DarkBlue; Console.WriteLine("(3) Finish Transaction"); Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine($"Current Money Provided: {vendoMatic500.Balance:c2} "); Console.ResetColor(); string choice = GetString(">Please enter your choice."); if (choice == "1") { vendoMatic500.Balance = FeedMoney(vendoMatic500.Balance); Console.Clear(); PurchaseMenu(vendoMatic500); } else if (choice == "2") { //Display Items for user to see what's there and make a choice //vendoMatic500.Display(); DisplayInventory(vendoMatic500); string productChoice = ""; while (true) { //Prompt user for item and hold choice in variable productChoice = GetString(">Please enter the slot of your choice.").ToUpper(); if (vendoMatic500.VendingMachineItems.ContainsKey(productChoice) && vendoMatic500.IsItemInStock(productChoice))//Checking if in stock { break; } else if (!vendoMatic500.VendingMachineItems.ContainsKey(productChoice)) { Console.WriteLine("That code does not exist. TRY AGAIN."); Console.ReadLine(); } //Check to see if the item selected is sold out else if (vendoMatic500.VendingMachineItems[productChoice].Quantity == 0) { Console.WriteLine("Item is sold out :("); Console.ReadLine(); } } //Dispense item - if quantity is available and they have enough money and if code exists if (vendoMatic500.Balance >= vendoMatic500.VendingMachineItems[productChoice].Price) { vendoMatic500.Dispense(productChoice); } else { Console.WriteLine("Insufficient funds. Please feed me money."); Console.ReadLine(); Console.Clear(); PurchaseMenu(vendoMatic500); } //Update the audit report LogMessage($"{vendoMatic500.VendingMachineItems[productChoice].ProductName} {productChoice} ", vendoMatic500.Balance + vendoMatic500.VendingMachineItems[productChoice].Price, vendoMatic500.Balance); //Return to purchase menu Console.Clear(); PurchaseMenu(vendoMatic500); } //Finish Transaction else if (choice == "3") { Console.Clear(); //Return the customer's money in quarters, dimes, nickels (using smallest amount possible) //Look at the Balance and Call method to calculate return money PrintChange(vendoMatic500); //Update machine's balance to $0 vendoMatic500.Balance = 0; Console.WriteLine($"Balance: {vendoMatic500.Balance}"); Console.ReadLine(); Console.Clear(); } else { Console.WriteLine("Invalid Option"); Console.ReadLine(); Console.Clear(); PurchaseMenu(vendoMatic500); } }