Solved

error message

Posted on 2000-03-14
12
379 Views
Last Modified: 2010-04-10
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

0
Comment
Question by:nationnon
  • 8
  • 4
12 Comments
 
LVL 1

Author Comment

by:nationnon
ID: 2616439
: 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
 
LVL 7

Accepted Solution

by:
KangaRoo earned 35 total points
ID: 2616448
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
 
LVL 1

Author Comment

by:nationnon
ID: 2616520
Adjusted points from 10 to 15
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 1

Author Comment

by:nationnon
ID: 2616521
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
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2616546
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
 
LVL 1

Author Comment

by:nationnon
ID: 2616817
Adjusted points from 15 to 25
0
 
LVL 1

Author Comment

by:nationnon
ID: 2616818

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
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2618945
Huh? how can that be???
Can you paste the code, or which of the above did you use?
0
 
LVL 1

Author Comment

by:nationnon
ID: 2620753
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
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2635297
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
 
LVL 1

Author Comment

by:nationnon
ID: 2635626
Adjusted points from 25 to 35
0
 
LVL 1

Author Comment

by:nationnon
ID: 2635627
I figured it out.  I had to define the variables which was very simple. totalDeductions = .45;
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question