public string AddMoney(string userInput) { string result = ""; decimal inputAmount = 0M; try { inputAmount = decimal.Parse(userInput); } catch (FormatException ex) { result = ex.Message; return(result); } if (inputAmount + Balance > 5000M) { result = "Amount too large. Balance limitd to $5000"; } else if (inputAmount != Math.Ceiling(inputAmount) || inputAmount != Math.Floor(inputAmount)) { result = "Amount must be whole dollar amount."; } else { Balance += inputAmount; FileAccess fa = new FileAccess(); fa.WriteLog("Add money", inputAmount, Balance); } return(result); }
public bool MakePurchase(string product, string quanity) { bool result = false; int count = int.Parse(quanity); foreach (CateringItem item in inventory) { if (item.ProductCode == product) { Balance -= item.Price * count; item.Quanity -= count; FileAccess fa = new FileAccess(); fa.WriteLog("Purchase " + item.ProductName, Balance + (item.Price * count), Balance); CateringItem newItem = new CateringItem(item.ProductCode, item.ProductName, item.Price, item.ProductType, count); purchases.Add(newItem); result = true; break; } } return(result); }
public string MakeChange() { string result = ""; Dictionary <string, int> currency = new Dictionary <string, int>(); currency["Twenty"] = 2000; currency["Ten"] = 1000; currency["Five"] = 500; currency["One"] = 100; currency["Quarter"] = 25; currency["Dime"] = 10; currency["Nickle"] = 5; int cents = (int)(Balance * 100); foreach (KeyValuePair <string, int> item in currency) { if (cents / item.Value > 0) { result += (cents / item.Value) + " - " + item.Key + ", "; cents = cents % item.Value; } } //remove the last 2 characters (", ") if (result.Length > 2) { result = result.Substring(0, result.Length - 2); } FileAccess fa = new FileAccess(); fa.WriteLog("Return change", Balance, 0M); //set balance to zero Balance = 0M; return(result); }