Link to home
Start Free TrialLog in
Avatar of nationnon
nationnon

asked on

error message

good morning,
i'm getting an error message and I was wondering if anyone knew what this means.

error C2297: '*' : illegal, right operand has type 'float (__cdecl *)(float)'
 
here is the line it says the error is on:

return input * totalDeduction;

here is the complete function :
float totalDeduction(float input)
{
double deduction = 0.425;
return input * totalDeduction;
} //end of calcDeductions function

Avatar of nationnon
nationnon

ASKER

: warning C4305: 'initializing' : truncation from 'const double' to 'float'

is the warning message when I change double deduction into float deduction.

but i'm not so worried about that.
ASKER CERTIFIED SOLUTION
Avatar of KangaRoo
KangaRoo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Adjusted points from 10 to 15
now it's a warning message stating that
: warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data

the line it's on is
return input * deduction;



That's correct, the function returns a float. It calculates with doubles however, because deduction is declared as a double. two solutions:

float totalDeduction(float input)
{
     float deduction = 0.425;
     return input * deduction;
}

// Or:

double totalDeduction(double input)
{
     double deduction = 0.425;
     return input * deduction;
}
Adjusted points from 15 to 25

I have one last warning and it is warning C4700: local variable 'deduction' used without having been initialized

If i'm not mistaken the variable has been initialized.  Do I have to go add (float) deduction 0.0; after the normal float deduction; , will that fix it? and what will it do if it does fix it?


Huh? how can that be???
Can you paste the code, or which of the above did you use?
the  double totalDeduction(double input)
{
     double deduction = 0.425;
     return input * deduction;
}

got rid of one warning.

but there are two warnings
: warning C4700: local variable 'deduction' used without having been initialized

warning C4700: local variable 'grossIncome' used without having been initialized





In the totalDeduction function 'deduction' is initialized in the very first line. I haven't seen 'grossIncome' before. Check the line numbers the compiler gives with the warnings, I suspect they refer to another function.
Adjusted points from 25 to 35
I figured it out.  I had to define the variables which was very simple. totalDeductions = .45;