C#C
C#3y ago
Mek

✅ Switch Case Not Executing Properly

public static void ShowMenu(string username, string date)
{
    string choice = GetMenuChoice();
    string difficulty = GetGameDifficulty();
    int maxQuestions = GetNumberOfQuestions();

    switch (choice)
    {
        case "Addition":
        case "Subtraction":
        case "Multiplication":
        case "Division":
        case "Random":
            Game.StartGame(username, date, choice, difficulty, maxQuestions);
            break;

        case "Previous Games":
            Game.ShowPreviousGames();
            break;

        case "Quit Game":
            ColorCon.WriteLine("Exiting Application", ConsoleColor.Red);
            Environment.Exit(0);
            break;
    }
}

public static string GetMenuChoice()
{
    Console.Clear();
    string menuOptions = """
                            What Would You Like To Do?

                            A - Addition
                            S - Subtraction
                            M - Multiplication
                            D - Division
                            R - Random
                            P - Previous Games
                            Q - Quit Game
                             
                             
                            Your Selection: 
                            """;
    List<string> choices = new() { "a", "s", "m", "d", "r", "p", "q" };
    string errorText = "Invalid Input. Choice Must Be: \"A\", \"S\", \"M\", \"D\", \"R\", \"P\", or \"Q\"";

    string choice = ColorCon.GetStringFromConsole(
        prompt: menuOptions,
        color: ConsoleColor.Cyan,
        validator: x => choices.Contains(x.ToLower()),
        errorMessage: errorText);

    return choice switch
    {
        "a" or "A" => "Addition",
        "s" or "S" => "Subtraction",
        "m" or "M" => "Multiplication",
        "d" or "D" => "Division",
        "r" or "R" => "Random",
        "p" or "P" => "Previous Games",
        "q" or "Q" => "Quit Game",
        _ => throw new Exception("Sum Ting Wong")
    };
}
no matter what I enter in for my choice, the switch case in the top function always runs Game.StartGame(). What do I have wrong?
Was this page helpful?