2

I'm a beginner in programming, and i'm really wondering what's my mistake here :

static void Main(string[] args)
{
    int a = int.Parse(Console.ReadLine());
    int b = int.Parse(Console.ReadLine());
    int c = int.Parse(Console.ReadLine());

    if ((a > b) && (a > c))
    {
       Console.WriteLine(a);
    }
    else
    {
       if ((b > a) && (b > c)) ;
       {
          Console.WriteLine(b);
       }
       else
       {
          Console.WriteLine(c);
       }
    }
}
Omar
  • 15,543
  • 9
  • 43
  • 64
user1866925
  • 218
  • 2
  • 9
  • See [this thread](http://stackoverflow.com/questions/8706139/what-happens-when-one-places-a-semi-colon-after-a-while-loops-condition) for why your semicolon after the if statement is incorrect. – SWalters Dec 12 '12 at 19:40
  • In the line `if ((b > a) && (b > c))` you don't need the `(b > a)`. You already know `a` is not the largest, you only care about `b` and `c`. – Servy Dec 12 '12 at 19:41

2 Answers2

13
if ((b > a) && (b > c)) ;

Remove the ;

Jared Harley
  • 8,091
  • 4
  • 38
  • 48
BlackBear
  • 21,554
  • 9
  • 45
  • 82
1

You can't use in your if condition ;. Remove it.

if ((b > a) && (b > c))
{
      Console.WriteLine(b);
}

And you need one more } end of you code.

Edit: Actually you can use ; with your if condition. For example;

if ((b > a) && (b > c));

is equal

if ((b > a) && (b > c))
{

}
Soner Gönül
  • 94,086
  • 102
  • 195
  • 339