Homework Help

This is a discussion on Homework Help within the C Programming forums, part of the General Programming Boards category; I'm taking a C programming class and im in need of help for my homework. My else statements dont work ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    1

    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

  2. #2
    Registered User
    Join Date
    Jul 2010
    Location
    Oklahoma
    Posts
    107
    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: << !! Posting Code? Read this First !! >>, and another that may be helpful: http://cboard.cprogramming.com/c-pro...e-posting.html

    Best Regards,

    New Ink -- Henry
    Last edited by new_ink2001; 10-01-2010 at 12:15 AM. Reason: to include the forum's standards
    Kept the text books....
    Went interdisciplinary after college....
    Still looking for a real job since 2005....

    During the interim, I may be reached at ELance, vWorker, FreeLancer, oDesk and WyzAnt.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Homework
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 11-03-2001, 03:39 PM
  2. Homework
    By kermi3 in forum C Programming
    Replies: 10
    Last Post: 09-27-2001, 04:49 PM
  3. Homework
    By kermi3 in forum Windows Programming
    Replies: 5
    Last Post: 09-15-2001, 11:48 AM
  4. Homework
    By kermi3 in forum C Programming
    Replies: 0
    Last Post: 09-10-2001, 01:26 PM

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