Hi,

I just started taking a programming class and am having trouble figuring out why this wont program wont work correctly. The user inputs their coordinates and the program returns whether it is in quadrants 1,2,3,4 or on an axis or the origin.

#include <stdio.h>

int
main(void)
{
        double   xcoord,
                 ycoord;

        printf("$ quadrant\n");
        printf("Please enter the x and y coordinates: ");
        scanf("%lf %lf",&xcoord,&ycoord);

        if (xcoord==0 && ycoord==0)
        {
                printf("(%lf,%lf) is on the origin\n",xcoord,ycoord);
        }
        else if (ycoord==0 && xcoord!=0)
        {
                printf("(%lf,%lf) is on the x axis\n",xcoord,ycoord);
        }
        else if (xcoord==0 && ycoord!=0)
        {
                printf("(%lf,%lf) is on the y axis\n",xcoord,ycoord);
        }
        else if (xcoord>0 && ycoord>0)
        {
                printf("(%lf,%lf) is in quadrant I\n",xcoord,ycoord);
        }
        else if (xcoord<0 && ycoord<0)
        {
                printf("(%lf,%lf) is in quadrant III\n",xcoord,ycoord);
        }
        else if (xcoord>0 && ycoord<0)
        {
                printf("(%lf,%lf) is in quadrant IV\n",xcoord,ycoord);
        }
        else if(xcoord<0 && ycoord>0);
        {
                printf("(%lf,%lf) is in quadrant II\n",xcoord,ycoord);
        }

        return(0);
}

This is my code and it complies but the results spit out as:

$ quadrant
Please enter the x and y coordinates: 1.0 2.5
(1.000000,2.500000) is in quadrant I
(1.000000,2.500000) is in quadrant II

I know how to fix the multiple decimal points with %.1lf but I dont get why it is printing out multiple statements. Also, there is no need for error checking as of now as our professor stated for the time being we can assume a perfect user

Look very closely

else if(xcoord<0 && ycoord>0);

Notice the semi-colon.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.