C: Enter coordinate and get out a quadrant

This is a discussion on C: Enter coordinate and get out a quadrant within the C Programming forums, part of the General Programming Boards category; The task is to create a c source code program that will name a quadrant when a given coordinate is ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    36

    C: Enter coordinate and get out a quadrant

    The task is to create a c source code program that will name a quadrant when a given coordinate is given.
    Example:
    Input Coordinate Pair: 0 5.3
    Positive y Axis

    I need help on how to start this. I know I have to use if else statements but I'm not sure how to work those. I was wondering if someone could help me start off? Thanks.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So how do you, yourself, know that (0,5.3) is on the positive y-axis? What is true about all the points on the positive y-axis?

    Ditto for all the quadrants: what has to be true about (x,y) for the point to be in (say) quadrant III?

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    36
    Alright, so this is what I came up with so far.

    But I'm getting an error:invalid lvalue in assignment on line 20 and 22. Am I doing the else if statements wrong?

    Code:
    /* Directives */
    
    #include <stdio.h>
    #include <math.h>
    
    int main(void)
    
    {
    
    int x, y;
    
    printf("Enter coordinate pair: ");
    scanf("%d %d", &x, &y);
    if (x = 0 && y > 0)
    printf("Positive y Axis");
    else if (x > 0 && y = 0)
    printf("Positive x Axis");
    else if (x < 0 && y = 0)
    printf("Negative x Axis");
    else if (x = 0 && y < 0)
    printf("Negative y Axis");
    
    
    /* End Program */
    return(0);
    }

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    There's a difference between = and ==.

  5. #5
    Registered User
    Join Date
    Sep 2009
    Posts
    36
    Oh! Missed that definition. Thanks!

  6. #6
    Registered User
    Join Date
    Sep 2009
    Posts
    36
    Wait, even though I'm getting the right answers from the program, the grader program is telling me it's not 100% correct. Is there a way I could rewrite the if statements to have the "if else" statements? I'm thinking it's looking for the "if else" statements.
    Last edited by gnozahs; 09-24-2009 at 12:07 AM.

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Is the grader program looking at your source code, or just your output? (If the latter, then it doesn't matter whether you use else if; but also, it's probably using input that it may not be telling you about -- in other words, just because it works on your one or two sample inputs doesn't mean it actually works.)

  8. #8
    Registered User
    Join Date
    Sep 2009
    Posts
    36
    Ok, so I changed all the other previous "if"except the first "if to "else if" and the int x, y to float x, y since the grader program said it wanted x and y to be float.

    The grader program finally accepted it. Thanks!!!

  9. #9
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,832
    I wouldn't have passed you. You haven't identified the quadrant. That is, if neither coordinate is zero??? Where does the program go if both are zero?

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21