0

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

2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by gerard4143
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.