//Run the switch statment after we've printed the menu public void Start() { //Define Variables int choice = -1; while (true) { WriteMenuText(); choice = int.Parse(Console.ReadLine()); //Write user input to choice, after we've checkat that it's a int. else we crash, could be handled by tryParse instead. switch (choice) //direct the user to the right menu, based on the choice made { case 1: //menu1 WholeNumbersFor WHF = new WholeNumbersFor(); WHF.Start(); break; case 2: //menu2 FloatingNumberWhile FNW = new FloatingNumberWhile(); FNW.Start(); break; case 3: //Menu3 ExchangeDoWhile EDW = new ExchangeDoWhile(); EDW.Start(); break; case 4: //Menu4 WasteSchedule WS = new WasteSchedule(); WS.Start(); break; case 5: //Menu4 WriteMessageCodeNotImplemented(choice); //Just to give an option to test the error message break; case 0: //Exit Program Environment.Exit(0); //Kill the program break; } } }
public void Start() { int choice = -1; while (choice != 0) { WriteMenuText(); // show the menu // read the users choice choice = int.Parse(Console.ReadLine()); // perform the different operations of the menu depending on the choice of the user switch (choice) { // Whole numbers with For case 1: { // Declare a local reference variable and create an instance of WholeNumbersFor WholeNumbersFor wholeNumbersFor = new WholeNumbersFor(); wholeNumbersFor.Start(); break; } // Floating numbers with While case 2: { // Declare a local reference variable and create an instance of FloatingNumbersWhile FloatingNumbersWhile floatingNumberWhile = new FloatingNumbersWhile(); floatingNumberWhile.Start(); break; } // Currency Convertor with Do-While loop case 3: { // Declare a local reference variable and create an instance of CurrencyConvDoWhile CurrencyConvDoWhile currencyConvDoWhile = new CurrencyConvDoWhile(); currencyConvDoWhile.Start(); break; } // Waste Schedule case 4: { // Declare a local reference variable and create an instance of WasteSchedule WasteSchedule wasteSchedule = new WasteSchedule(); wasteSchedule.BinStart(); break; } // exit the program default: { if (choice == 0) { Environment.Exit(0); } else { Console.WriteLine("Please enter choice between 1 to 4 (or) 0 to exit the program"); } break; } } } }
public void Start() { int choice = -1; while ( choice != 0 ) { WriteMenuText(); // show the menu // read the users choice choice = int.Parse(Console.ReadLine()); // perform the different operations of the menu depending on the choice of the user switch(choice) { // Whole numbers with For case 1: { // Declare a local reference variable and create an instance of WholeNumbersFor WholeNumbersFor wholeNumbersFor = new WholeNumbersFor(); wholeNumbersFor.Start(); break; } // Floating numbers with While case 2: { // Declare a local reference variable and create an instance of FloatingNumbersWhile FloatingNumbersWhile floatingNumberWhile = new FloatingNumbersWhile(); floatingNumberWhile.Start(); break; } // Currency Convertor with Do-While loop case 3: { // Declare a local reference variable and create an instance of CurrencyConvDoWhile CurrencyConvDoWhile currencyConvDoWhile = new CurrencyConvDoWhile(); currencyConvDoWhile.Start(); break; } // Waste Schedule case 4: { // Declare a local reference variable and create an instance of WasteSchedule WasteSchedule wasteSchedule = new WasteSchedule(); wasteSchedule.BinStart(); break; } // exit the program default: { if (choice == 0) { Environment.Exit(0); } else { Console.WriteLine("Please enter choice between 1 to 4 (or) 0 to exit the program"); } break; } } } }