//check for packages that are the same *possible future upgrade // public Sliced getPackageSli(string package) // { // Sliced toCart; // foreach (Sliced item in _Sliced) // { // if (package == item._pack) // { // return toCart = item; // } // } // return null; // } public void AddYo(Yoghurt GroceryToBeAdded) { _Yoghurt.Add(GroceryToBeAdded); }
public static void DoYoghurt(CartHandle accounted) { int amount; int quotient = 0; int quotient2 = 0; int quotient3 = 0; int quotient4 = 0; int quotient5 = 0; int remainder = 0; int remainder2 = 0; int handle = 0; Console.WriteLine("Please enter number of Yoghurt to be purchased: "); amount = Convert.ToInt32(Console.ReadLine()); int amountDouble = amount; handle = quotient = Math.DivRem(amount, 15, out remainder); Yoghurt newCart = new Yoghurt(handle, "15"); Yoghurt newCart2 = new Yoghurt(quotient2, "10"); Yoghurt newCart3 = new Yoghurt(quotient3, "4"); Yoghurt newCart4 = new Yoghurt(quotient4, "10"); Yoghurt newCart5 = new Yoghurt(quotient5, "4"); //first loop in if 15 is applicable if (remainder > 0) { handle = quotient2 = Math.DivRem(remainder, 10, out amountDouble); newCart2 = new Yoghurt(handle, "10"); if (amountDouble == 0) { accounted.AddYo(newCart); accounted.AddYo(newCart2); } else if (amountDouble > 0) { handle = quotient3 = Math.DivRem(amountDouble, 4, out remainder); newCart3 = new Yoghurt(quotient3, "4"); //sustain and wait if (remainder == 0) { accounted.AddYo(newCart); accounted.AddYo(newCart2); accounted.AddYo(newCart3); } else if (remainder > 0) // see if you start with 10 { handle = quotient4 = Math.DivRem(amount, 10, out remainder2); newCart4 = new Yoghurt(handle, "10"); if (remainder2 > 0) { // see if you can get no remainder with this handle = quotient5 = Math.DivRem(remainder2, 4, out amountDouble); newCart5 = new Yoghurt(handle, "4"); if (amountDouble == 0) { accounted.AddYo(newCart4); accounted.AddYo(newCart5); } else if (amountDouble > 0) { Console.WriteLine("please enter a valid Pack"); } } } } else { Console.WriteLine("Please enter valid packs"); } } else if (remainder == 0) { accounted.AddYo(newCart); } accounted.PrintY(); }