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
  • 16,329
  • 10
  • 48
  • 66
user1866925
  • 338
  • 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,219
  • 4
  • 39
  • 48
BlackBear
  • 22,411
  • 10
  • 48
  • 86
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
  • 97,193
  • 102
  • 206
  • 364