0

I tried to print the largest number in the array but there's an error showing misplaced else. I tried putting brackets around but there's still an error in it. I don't have an idea why there is a misplaced else error. Please help : >.<

#include <stdio.h>
#include <conio.h>

void main()
{
  int lar, yem;
  clrscr();
  int aray[10];
  for (yem = 0; yem < 10; ++yem)
  {
    printf("Input numbers:");
    scanf("%d", &aray[yem]);
  }

  lar = aray[0];

  for (yem = 1; yem < 10; ++yem)
  {
    if (aray[yem] > lar);
      lar = aray[yem];
    else
      ++yem;

    printf("Biggest: %d\n", lar);
   }
    getch();
}
haccks
  • 104,019
  • 25
  • 176
  • 264
deibaby03
  • 5
  • 1
  • 4
  • 3
    OT: It's `int main(void)`. – alk Sep 28 '13 at 10:36
  • 3
    @alk: If only...please read [What should `main()` return in C and C++](http://stackoverflow.com/questions/204476/what-should-main-return-in-c-and-c/18721336#18721336) where you'll find Microsoft has subverted the rule about `int main()`. – Jonathan Leffler Sep 28 '13 at 10:43

3 Answers3

3

Remove the semicolon ; from the if statement;

if(aray[yem]>lar);
                 ^
                 |  
            Remove this  
haccks
  • 104,019
  • 25
  • 176
  • 264
3
 if(aray[yem]>lar);
                  ^^ get rid of this semi-colon

Use of this semi-colon will be equivalent to

 if(aray[yem]>lar)
    ;
 lar=aray[yem];

 else //Now this else doesn't have a matching if hence the error
 ...
P0W
  • 46,614
  • 9
  • 72
  • 119
2

You are terminating an if statement with ;

if(aray[yem]>lar);
                 ^         
                 |

Delete the ; at the end

if(aray[yem]>lar)
OBV
  • 1,169
  • 1
  • 12
  • 25