# 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

LVL 1
###### Who is Participating?

Commented:
You are trying to multiply the float 'input'ith the function pointer 'totalDeduction'. Maybe you wanted this:

float totalDeduction(float input)
{
double deduction = 0.425;
return input * deduction;
} //end of calcDeductions function
0

Author Commented:
: 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.
0

Author Commented:
Adjusted points from 10 to 15
0

Author Commented:
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;

0

Commented:
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;
}
0

Author Commented:
Adjusted points from 15 to 25
0

Author Commented:

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?

0

Commented:
Huh? how can that be???
Can you paste the code, or which of the above did you use?
0

Author Commented:
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

0

Commented:
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.
0

Author Commented:
Adjusted points from 25 to 35
0

Author Commented:
I figured it out.  I had to define the variables which was very simple. totalDeductions = .45;
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.