Jiskha Homework Help
SATURDAY
November 21, 2009
SCHOOL SUBJECTS
- Art
- Business
- Computers
- English
- Foreign Languages
- Health
- Home Economics
- Math
- Music
- Physical Education
- Science
- Social Studies
GRADE LEVELS
- Preschool
- Kindergarten
- Elementary School
- 1st Grade
- 2nd Grade
- 3rd Grade
- 4th Grade
- 5th Grade
- 6th Grade
- 7th Grade
- 8th Grade
- High School
- 9th Grade
- 10th Grade
- 11th Grade
- 12th Grade
- College
- Adult Education
Post a New Question | Current Questions | Chat With Live Tutors

Homework Help Forum: C programming

Posted by Z32 on Wednesday, September 23, 2009 at 5:49pm.

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 just 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.

  • C programming - jim, Wednesday, September 23, 2009 at 7:26pm

    It's not too hard. Think that there are only these possibilities:

    Positive X, Positive Y
    Positive X, Negative Y
    Negative X, Positive Y
    Negative X, Negative Y

    and zero x and / or y

    OK, so your program will output one of 5 possible answers.

    You take in two numbers, call them x and y.

    Let's say you're building up a string to print at end. That's not the most elegant option, but it'll do.

    You don't actually need "else" statements, like:

    if (x < 0) strcpy (result, "Negative X, ");
    if (x > 0) strcpy (result, "Positive X, ");
    if (x == 0) ....

    if (y < 0) strcat (result, "Negative Y");
    if (y > 0) strcat ....
    if (y == 0) strcat ....


    Not the most elegant program, but you should be able to make it prettier once you have it running!


  • C programming - jim, Wednesday, September 23, 2009 at 7:29pm

    Oops, I meant 6 possible answers.

    While I'm here, remember strcpy puts the value into the string, and strcat appends it to the end of the string.

    Remember to be sure to declare result to be a char field (more than) big enough for what you're going to put in it.

  • C programming - Z32, Thursday, September 24, 2009 at 10:47pm

    Thanks for the input. I finally got it. Yeah!

Answer this Question

First Name:
School Subject:
Answer:

SEARCH

COMMUNITY
FEATURES
- Live Tutors
- Net Riddle
- Reference
- Search