Why am I getting so many error messages for my else statement?

For this lecture I was following along but by the end of the video I was getting many errors and I don’t understand why.

My lines of code are:
void OnUserInput(string input)
{
if(input == “menu”)
{
ShowMainMenu()
else
Terminal.WriteLine(“Please choose a valid level”);
}
}

But I receive errors such as :
; expected, ‘else’ cannot start a statement, syntax ‘(’ expected, invalid expression term ‘else’ and finally syntax ‘)’ expected.

Any help would be greatly appreciated as I can’t progress without fixing this issue first.
Thanks in advance

1 Like

Welcome to the community!

If you copied your code exactly as it is, there are a lot of issues with it.

I’ll point them out with comments (The green text after two forward slashes “//”).

void OnUserInput(string input)
{
    if(input == “menu”)
    {
        ShowMainMenu() //<--- You are missing a ";"
                       //<--- Closing bracket missing "}"
    else
                       //<--- Opening bracket missing "{"
        Terminal.WriteLine(“Please choose a valid level”);
    }
}

@Yee Thanks so much, this fixed my issues. :slightly_smiling_face: Also thanks for the fast reply.

Glad I could help :smiley:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.