user1866925
user1866925

Reputation: 356

Finding the biggest number of three using if-else. Why it doesn't want to compile?

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);
       }
    }
}

Upvotes: 2

Views: 1830

Answers (2)

BlackBear
BlackBear

Reputation: 22989

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

Remove the ;

Upvotes: 13

Soner Gönül
Soner Gönül

Reputation: 98810

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))
{

}

Upvotes: 1

Related Questions