} // Grabs a double and returns it //Display Menu static void displayAndGrabMenuOption() { /* * All you have to do is add the function name to the list and list options and your set * The list calls it and then loops back to Main. * Making sure that the user input is a number was more work. */ int method_to_run; string[] list_options = { "Package price finder", "Temperature to array", "Book Discounts", "Overtime Calculator", "Lots of Numbers", "Lots of Strings" }; // Names of Menu options List <Action> functionList = new List <Action>(); // Makes a new list to hold the functions functionList.AddRange(new Action[] { runPackagePrice, tempPushArray, howManyBooks, hoursWorked, intHandling, stringHandling }); // Adds functions to the lists // Loops thru menu options for (int i = 0; i < list_options.Length; i++) { Console.WriteLine("{0}: {1}", i + 1, list_options[i]); } method_to_run = StringParse.Int("Pick an option from 1 to " + list_options.Length); functionList[method_to_run - 1](); Console.Clear(); } // Holds the method calls and menu options
} // Uses the list Distinct call and displays all of it static void findValue(double[] data) { int arr_value; List <int> positions = new List <int>(); Console.WriteLine("Enter the digit you want to find. Will return all instances of value and place in array."); arr_value = StringParse.Int("Value"); for (int i = 0; i < data.Length; i++) { if (data[i] == arr_value) { positions.Add(i); } } Console.Write("{0} was found at positon(s): ", arr_value); foreach (int i in positions) { Console.Write(" |{0}| ", i); } Console.WriteLine(); } // Loops thru the array and checks for the given double. Returns position of array if found
} // Calculates overtime pay based on hours and given payrate // Book Thing static void howManyBooks() { int book_num; double book_price; double total_cost; double total_cost_discounted; double discount; Console.Write("How many books are you gonna need: "); book_num = StringParse.Int(); Console.Write("How much does the book cost: "); book_price = StringParse.Double(); discount = discountDecider(book_num); total_cost = book_num * book_price; total_cost_discounted = total_cost * discount; Console.WriteLine("You have received a discount of {0} off!", (discount).ToString("0%")); Console.WriteLine("Your total is {0}", (total_cost - discount).ToString("$0.00")); Console.WriteLine("Without the discount your total would have been {0}", (total_cost).ToString("$0.00")); Console.WriteLine("You saved {0} from your discount.", (total_cost_discounted).ToString("$0.00")); } // Calculates a discount rate and discount amount based on number of books bought
static void stringHandleMenu(List <string> data) { Console.Clear(); int menu_option_position; bool exit = false; string[] menu_titles = { "Find Entry" }; foreach (string i in menu_titles) { Console.WriteLine("{0}: {1}", i.IndexOf(i) + 1, i); } menu_option_position = StringParse.Int("Command Option [1/" + menu_titles.Length + "]"); switch (menu_option_position) { case 1: findEntry(data); break; case 6: exit = true; break; default: Console.WriteLine("Command not recognized"); break; } if (!exit) { stringHandleMenu(data); } }
static void intHandleMenu(double[] data) { int choice; bool exit = false; string[] options = { "List all Data", "Find Average", "Find all unique", "Find all Specific", "New Dataset", "Import Dataset", "Exit" }; Console.WriteLine("What do you want to do with the data set?"); for (int i = 0; i < options.Length; i++) { Console.WriteLine("{0}: {1}", i + 1, options[i]); } // This just lists the menu options Console.Write("Data: "); choice = StringParse.Int(); switch (choice) // Just picks the correct function to run { case 1: Console.Clear(); listAllData(data); break; case 2: Console.Clear(); findAverage(data); break; case 3: Console.Clear(); listUniq(data); break; case 4: Console.Clear(); findValue(data); break; case 5: Console.Clear(); intHandling(); break; case 6: Console.Clear(); intHandleMenu(importFile()); break; case 7: Console.Clear(); exit = true; break; default: Console.Clear(); Console.WriteLine("Command not recognized"); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); break; } if (!exit) { intHandleMenu(data); } } // Holds all the menu options for data handler