-3

I was trying to make a simple C program which, given X and Y coordinates, tells the quadrant. I'm getting an error:

cordinate.c: In function ‘main’:
cordinate.c:28:1: error: expected ‘;’ before ‘{’ token

As far as I know syntax-wise i's correct.

Code:

#include <stdio.h>
void main() {
    int x, y;

    printf("enter the cordinate x and y\n");
    scanf("%d%d",&x,&y);

    if ((x > 0) && (y > 0)) {
        printf("The point lies in 1st quadrant \n");
    } else if ((x < 0) && (y > 0)) {
        printf("The point lies in 2nd quadrant \n");
    } else if ((x < 0) && (y < 0)) {    
        printf("The point lies in 3rd quadrant \n");
    } else ( (x>0) && (y<0) )

    {   
        printf("The point lies in 4th quadrant \n");
    }
}

And when I do whatever is said I get the output as

input 
22
33
output
The point lies in 1st quadrant 
The point lies in 4th quadrant

Can anyone explain this?

Functino
  • 1,939
  • 17
  • 25
Akshdeep
  • 49
  • 6

3 Answers3

4
 else ( (x>0) && (y<0) )
 {   
       printf("The point lies in 4th quadrant \n");
  }

else doesnt take any condition. Use

 else if ( (x>0) && (y<0) )

or only else .

Sourav Kanta
  • 2,727
  • 1
  • 18
  • 29
2

After else there is no conditions, fix your program like this:

 #include<stdio.h>
  void main()
 {
    int x,y;

    printf("enter the cordinate x and y\n");
    scanf("%d%d",&x,&y);

    if((x>0) && (y>0))
    {
        printf("The point lies in 1st quadrant \n");
    }  
    .
    .
    .

    else   // The condition removed form here
    {   
        printf("The point lies in 4th quadrant \n");
    }
}

else means that if all conditions fails then it will execute what is after else so there no need to specify condition after it.

Nasr
  • 2,482
  • 4
  • 26
  • 31
2

It looks like you're missing an if keyword on this line:

} else ( (x>0) && (y<0) )

Also, you shouldn't use void main(). You can only use either int main(void) or int main(int argc, char **argv).

Community
  • 1
  • 1
Functino
  • 1,939
  • 17
  • 25