/// <summary> /// List a one line summary of all the posts and /// allow the user to select one by position in /// the list. First position = 1 /// </summary> public Post SelectPost() { string[] choices = new string[Posts.Count]; int i = 0; foreach (Post post in Posts) { choices[i] = post.GetSummary(); i++; } Console.WriteLine("\n Listing of all Posts"); int choiceNo = UserLib.SelectChoice(choices); return(Posts[choiceNo - 1]); }
/// <summary> /// Prompt the user to select imperial or metric /// units for entering their weight and height /// </summary> private UnitSystem SelectUnits() { string[] choices = new[] { "Metric Units", "Imperial Units" }; int choice = UserLib.SelectChoice(choices); if (choice == 1) { return(UnitSystem.Metric); } else { return(UnitSystem.Imperial); } }
/// <summary> /// Display a menu of distance units and then prompt the /// user to select one and return it. /// </summary> private DistanceUnit SelectUnit(string prompt) { Console.WriteLine(prompt); string[] choices = { $" {DistanceUnit.Feet}", $" {DistanceUnit.Metres}", $" {DistanceUnit.Miles}" }; int choice = UserLib.SelectChoice(choices); DistanceUnit unit; if (choice == 1) { unit = DistanceUnit.Feet; } else if (choice == 2) { unit = DistanceUnit.Metres; } else { unit = DistanceUnit.Miles; } Console.WriteLine($" You have selected {unit}"); Console.WriteLine(); // Alternative to the if..else //switch (choice) //{ // case "1": unit = DistanceUnit.Feet; break; // case "2": unit = DistanceUnit.Metres; break; // case "3": unit = DistanceUnit.Miles; break; // default: unit = "INVALID CHOICE"; break; //} return(unit); }
public void OutputMenu() { string[] choices = { "Input Marks", "Output Marks", "Output Stats", "Output Grade Profile", "Quit" }; int choiceNo; do { UserLib.OutputHeading(" Students Grades App"); choiceNo = UserLib.SelectChoice(choices); switch (choiceNo) { case 1: InputMarks(); break; case 2: OutputMarks(); break; case 3: CalculateStats(); OutputStats(); break; case 4: CalculateGradeProfile(); OutputGradeProfile(); break; default: break; } } while (choiceNo != 5); }
public static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("BNU CO453 Applications Programming 2020-2021!"); Console.WriteLine(); Console.Beep(); Console.WriteLine("|1. Distance converter"); Console.WriteLine("|2. BMI calculator"); Console.WriteLine("|3. Student Marks"); string input = Console.ReadLine(); switch (input) { case "1": { DistanceConverter converter = new DistanceConverter(); converter.Convert(); break; } case "2": { BMI calculator = new BMI(); calculator.Main(); break; } case "3": { StudentGrades studentGrades = new StudentGrades(); UserLib.SelectChoice(studentGrades); break; } } }