Need help on basic C# code. Error cannot start statement with else

        if (num1 == num2)
        {
            if (num2 == num3)
                Write("All numbers are equal.");

            else
                {
                Write("Only integers one and two are equal");
                }        //THIS IS WHERE THE ERROR COMES UP. CANT I USE BRACKETS IN AN ELSE STATEMENT? THE ERROR SAYS CANT START STATEMENT WITH ELSE.
                
        else
            {
                Write("Only integers one and three are equal.");
            } 
        }
        ReadLine();

Hi @benziamm !

The if statement above the else is missing the curly brackets surrounding it, once you add those it should work :slightly_smiling_face:

Also, I might be missing something here, but why are you using ReadLine() instead of the full Console.ReadLine()?

-Lyall

This doesn’t seem to fix the problem. And im not using Console.Readline() because im using this at the top of the code>>> “using static System.Console”

Hi @benziamm!

At the moment the closing } for the first else surrounds the if statement, when it should come before it, for example at the moment you have:

  if (num1 == num2)
        {
           //CODEHERE
        else
            {
                Write("Only integers one and three are equal.");
            } 
        } //this bracket

When the curly bracket should be:

  if (num1 == num2)
  {
           //CODEHERE
  } //this bracket
  else
  {
      Write("Only integers one and three are equal.");
  } 

Like this? Still isn’t working.

Can you paste the code in as a codebyte/block? It’s difficult to see as a photo :slight_smile:

        if (num1 == num2)
        {
        }
            if (num2 == num3)
            {
                Write("All numbers are equal");
            }
            else
               {
                Write("Only integers one and two are equal");
               } 
                
        else
            {
                Write("Only integers one and three are equal.");
            }
        
        ReadLine();

So you’ll want the closing curly bracket of the if statement to below the if/else pair inside of it, but before it’s else statement:

``` if (num1 == num2) { if (num2 == num3) Write("All numbers are equal."); else { Write("Only integers one and two are equal"); } //THIS IS WHERE THE ERROR COMES UP. CANT I USE BRACKETS IN AN ELSE STATEMENT? THE ERROR SAYS CANT START STATEMENT WITH ELSE. else { Write("Only integers one and three are equal."); } } //this bracket here should be above the else statement ReadLine(); ```

With the first code you send becuase of the posisitoning of the }, the second else statement was inside of the relevant if statement, which isn’t valid :slight_smile:

YAY! Thank you. Appreciate the help. This was my first experience on Codecademy, thanks for making it great.

1 Like

No problem - happy to help! :grin: