static void Main(string[] args) { Restart: CT.Header(out CT.LengthOfTopLine, "Ch. 5 Program 10", " to re-do " + "the phone number prgm with arrays"); string[] DisplayNum = new string[10]; #region Mitch's Code /*Mitch take the stuff commented out right now... * its the right code for you... the rest is an even better way to do it... * DONT FORGET THE THREE METHODS AT THE BOTTOM!!!!!! * * * * List<string> OriginalNumbers = new List<string>(); * * CT.Color(""); * for (int i = 0; i < 10; i++) * { * string x = "Digit #" + (i + 1).ToString(); * OriginalNumbers.Add(AskUserForString(x)); * } * * DisplayNum = OriginalNumbers.ToArray(); * * Console.WriteLine("\n\nThe original phone number:"); * CT.Color("magenta"); * Console.WriteLine("({0} {1} {2}) {3} {4} {5} - {6} {7} {8} {9}", * DisplayNum[0], DisplayNum[1], DisplayNum[2], DisplayNum[3], DisplayNum[4], * DisplayNum[5], DisplayNum[6], DisplayNum[7], DisplayNum[8], DisplayNum[9]); * CT.Color(""); * * List<string> NewNumbers = new List<string>(); * * foreach (string num in OriginalNumbers) * { * NewNumbers.Add(ConvertToPhoneNumberEquivalent(num)); * } * * DisplayNum = NewNumbers.ToArray(); * * Console.WriteLine("\n\nThe useable phone number:"); * CT.Color("magenta"); * Console.WriteLine("({0} {1} {2}) {3} {4} {5} - {6} {7} {8} {9}", * DisplayNum[0], DisplayNum[1], DisplayNum[2], DisplayNum[3], DisplayNum[4], * DisplayNum[5], DisplayNum[6], DisplayNum[7], DisplayNum[8], DisplayNum[9]); * * Console.WriteLine(); * CT.AnyKeyToContinue(); * Console.Clear(); */ //End of Reg Prgm //The rest is just messing around #endregion List <string> OriginalNumbers2 = new List <string>(); string phoneNumber = CT.AskUserForString("the phone number with no spaces"); phoneNumber = phoneNumber.Trim(); while (phoneNumber.Contains(" ") || (phoneNumber.Contains("-")) || (phoneNumber.Length != 10)) { CT.Color("red"); Console.WriteLine("Please enter the phone number in the correct format!!"); phoneNumber = CT.AskUserForString("the phone number with no spaces"); } for (int i = 0; i < 10; i++) { OriginalNumbers2.Add(phoneNumber.Substring(i, 1)); } DisplayNum = OriginalNumbers2.ToArray(); int counter = 0; foreach (string check in OriginalNumbers2) { string intialNum = check; string checkedNum = ""; checkedNum = CheckNum2(check); if (intialNum != checkedNum) { DisplayNum[counter] = checkedNum; } counter++; } Console.WriteLine("\n\nThe original phone number:"); CT.Color("magenta"); Console.WriteLine("({0} {1} {2}) {3} {4} {5} - {6} {7} {8} {9}", DisplayNum[0], DisplayNum[1], DisplayNum[2], DisplayNum[3], DisplayNum[4], DisplayNum[5], DisplayNum[6], DisplayNum[7], DisplayNum[8], DisplayNum[9]); CT.Color(""); List <string> NewNumbers2 = new List <string>(); foreach (string num in DisplayNum) { NewNumbers2.Add(ConvertToPhoneNumberEquivalent(num)); } DisplayNum = NewNumbers2.ToArray(); Console.WriteLine("\n\nThe useable phone number:"); CT.Color("magenta"); Console.WriteLine("({0} {1} {2}) {3} {4} {5} - {6} {7} {8} {9}", DisplayNum[0], DisplayNum[1], DisplayNum[2], DisplayNum[3], DisplayNum[4], DisplayNum[5], DisplayNum[6], DisplayNum[7], DisplayNum[8], DisplayNum[9]); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("If you wish to enter another number, enter <-911>:"); string input = Console.ReadLine(); if (input == "-911") { Console.Clear(); goto Restart; } CT.Footer(); }
static void Main(string[] args) { CT.Header("Shopping List", ""); string fileName = Directory.GetCurrentDirectory(); fileName = fileName.Replace(@"\ShoppingList\bin\Debug", @"\ShoppingList.txt"); Preset(fileName); IfAddedMoreItems: StreamReader file = new StreamReader(fileName); int lineNum = 0; string line; string fruit; double quantity, price, totalCost = 0; while ((line = file.ReadLine()) != null) { string[] set = line.Split(','); fruit = set[0].Trim(); quantity = Convert.ToDouble(set[1].Trim()); price = Convert.ToDouble(set[2].Trim()); lineNum++; Item item = new Item(fruit, quantity, price); totalCost += item.Cost; Console.WriteLine("\nItem number {0}: {1}\nYou need {2}, each at {3:C}.\t\t" + "Current total -- {4:C}", lineNum, item.Name, item.Quantity, item.Price, totalCost); } CT.Color("magenta"); Console.WriteLine("\n\nThe total cost is {0:C}", totalCost); CT.Color("white"); Console.Write("Do you want to add any more items (Y/N): "); string moreItems = Console.ReadLine().ToLower(); List <string> NewItem = new List <string>(); int goToTop = 0; while (moreItems == "y") { goToTop++; moreItems = ""; Console.WriteLine("What would you like to add to your shopping list"); NewItem.Add(CT.AskUserForString("the fruit name") + ", " + CT.AskUserForDouble("the quantity of that fruit") + ", " + CT.AskUserForDouble("the price of each fruit") + ","); CT.Color("white"); Console.Write("Do you want to add any more items enter (Y/N): "); moreItems = Console.ReadLine().ToLower(); } file.Close(); if (goToTop > 0) { FileStream fappend = File.Open(fileName, FileMode.Append); StreamWriter writer = new StreamWriter(fappend); foreach (string newItem in NewItem) { writer.WriteLine(newItem); } writer.Close(); goto IfAddedMoreItems; } Console.WriteLine("Do you want to print a copy of your new shopping list (Y/N)"); if (Console.ReadLine().ToLower() == "y") { PrintCopy(fileName); } CT.Footer(); }