error messages

This is a discussion on error messages within the C Programming forums, part of the General Programming Boards category; If my function prototype is: Code: void ltb_calculation(double deduction, double *ltb, double *gross_pay); and my main function has the function(with ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    15

    error messages

    If my function prototype is:
    Code:
    void ltb_calculation(double deduction, double *ltb, double *gross_pay);
    and my main function has the function(with the variables declared as doubles):
    Code:
    ltb_calculation(deduction, *ltb, *gross_pay);
    and my function is:
    Code:
    void ltb_calculation(double deduction, double *ltb, double *gross_pay)
     {
      
    if (( *gross_pay / 100)  > 0)
    {
    *ltb= *gross_pay / 100;
    
     if (*ltb > 50)
     {
      
    *ltb == 50;
    
     }
    deduction= *ltb * 2;
    *gross_pay= *gross_pay - deduction;
    }
    }
    WHY do i get these error messages saying: "Function argument assignment between types "double*" and "double" is not allowed." ???
    I have a LOT of these messages as i did the same thing for each function. Some one help?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    To pass the a non-pointer variable to a function, you use the address-of operator, not the happy little star.
    Code:
    void foo( int *ptr )
    {
    }
    
    ...
    
    int x;
    
    foo( &x );

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    15
    Do you mean to change the main to:
    Code:
    ltb_calculation(deduction, &ltb, &gross_pay);
    Because i'm trying that, and still getting the same error message. I think i misunderstood you?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    That depends on what you have lbt and gross_pay declared as. See how simple it is to make a test case?
    Code:
    void ltb_calculation(double deduction, double *ltb, double *gross_pay)
    {
        /* do nothing of importance */
        if( ltb ) *ltb = 0.0;
        if( gross_pay ) *gross_pay = 0.0;
        deduction = 0.0;
    }
    
    int main( void )
    {
        double a, b, c;
    
        ltb_calculation( a, &b, &c );
    
        return 0;
    }
    Compile, run, be amazed!


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    15
    Thanks. Maybe next time you should try it without as much sarcasm.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    If I wanted your advice, I would have asked. Notice I didn't. Maybe by the nex time you ask, you'll have actually learned how to ask questions the smart way. Oh, since I'm here, you'll also notice that I answered your question correctly in the first post. If you hadn't have been so stupid, I wouldn't have had to answer the same question twice.


    Quzah.
    Hope is the first step on the road to disappointment.

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