# Homework Help

• 10-01-2010
Lasian
Homework Help
I'm taking a C programming class and im in need of help for my homework. My else statements dont work and i dont know what's wrong with them.I've looked at most websites and im doing exactly what they are doing except it still says its wrong. Here's the format...
FORMAT
After the prompt 'input coordinate pair: (you need the colon) you should input the variables x and y, (in that order) x and y should be float or double. The results should be origin, positive (negative) x (y) axis, or quadrant 1(2,3,4)
END FORMAT

Now this is what i have so far...

Code:

```#include<stdio.h> int main() { float x, y, origin, pos, neg, quad,  qone, qtwo, qthree, qfour; printf("Enter X Cord:\n"); scanf("%f",&x); printf("Enter Y Cord:\n"); scanf("%f",&y); if((x>0.0)&&(y>0.0)); { quad=qone; if((x<0.0)&&(y>0.0)); quad=qtwo; if((x<0.0)&&(y<0.0)); quad=qthree; if((x>0.0)&&(y<0.0)); quad=qfour; } if(x<0.0){ printf("The value is:negative\n"); } { else if(x == 0); printf("The value is zero\n"); else if; printf("The value is positive\n"); } if(y<0.0){ printf("The value is negative\n"); } { else if(y == 0); printf("The value is zero\n"); else if; printf("The value is positive\n"); } printf("The Origin is:%f, %f \n", x, y); printf("It's in quadrant:\n",quad); }```

If you can help me correct this and teach me WHY its wrong, it would be most appreciated :)
• 10-01-2010
new_ink2001
Lasian,

Will that source code even compile? What website suggested placing a semi-colon directly after your conditional statements? It reminds me of the Python format a little (rather a colon though), but in C they amount to a no-operation and execution continues after them...so the code that follows the conditional statement -- the statements you meant to be conditionally executed are all being executed as part of the program execution. Indention would make it a little easier to read too...

Check this out:

Code:

```if( a < b ) {   // this block only executes if a is less than b } else if( a > b ) {   // this block only executes if a is larger than b } else {   // this block only executes if a is equal to b }```
That might help explain why the process of implementing the algorithm is not working out.... Try those changes, and please let me know what you say. When you have a moment, I also recommend: http://cboard.cprogramming.com/c-pro...ead-first.html, and another that may be helpful: http://cboard.cprogramming.com/c-pro...e-posting.html

Best Regards,

New Ink -- Henry