Thread: A simple return and it does not work

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    1

    A simple return and it does not work

    Hey!

    I've been enjoying this board as a guest for a while now...I thought this would be a good time to post.

    Why on earth does this function not return what it should? Always 0, it always returns zero. It doesn't matter what number I put into skott_ar. I need help!!

    Code:
    int skott(double skott_ar)
    {
    double tal;
    double tal2;
    double tal3;
    
    tal=fmod(skott_ar,4);
    tal2=fmod(skott_ar,100);
    tal3=fmod(skott_ar,400);
        
        if (tal=0)
        {
           return 1;       
        } else{return 0;}
    }

    Thanks for your time...

    Christopher

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    = is an assignment operator

    == is a comparison operator
    Sent from my iPadŽ

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    post the entire program including header files so I can see the problem.

    i would of thought from the above, use a do while loop and not an if statement. but i need
    the whole program to understand it

  4. #4
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    change =

    to ==

  5. #5
    Registered User
    Join Date
    Jan 2006
    Posts
    20
    Yes, you now assign tal the number 0. You don't check if the number is equal to zero. So it will break out of the if statement.

    Change if(tal = 0) to if(tal == 0)

Popular pages Recent additions subscribe to a feed