Hello poohbear,
You should always compile your program before posting. This way if there any error messages that yo do not understand you can include them. It is best to post the actual complete error message.
In the function "getcommisions()" there are 8 errors that need to be corrected. I will give you a hint on one
else if (salesAmt >=4000 && <=8000)
. This is wrong. On the rhs of && there is nothing to evaluate. It should be
else if (salesAmt >=4000 && salesAmt <=8000)
. Your way would be nice, but that is not the way C++ is designed.
As nuderobmonkey suggested use the gear icon at the top right of the code block. When you press "run" the compiler will give you the errors and warnings.
Such as:
In member function 'double SalesRep::getcommisions()':
81:5: error: 'salesAmt' was not declared in this scope
94:1: warning: no return statement in function returning non-void [-Wreturn-type]
|
The first error is simple the variable "salesAmt" was not defined anywhere in the function.
I do agree that the warning is harder to understand. First keep in mind that the warning is on the closing brace of the function. This is not where the error has started. It actually started at line 82.
A push in the right direction. You have the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
double SalesRep:: getcommisions()
{
float commission;
if(salesAmt <=8000)
commission = .10 * salesAmt
else if (salesAmt >=4000 && <=8000)
commission = .07 * salesAmt
else if (salesAmt<4000)
commission = .10 * salesAmt
else //anything over 4000
commission = 0 * salesAmt
return commission;
}
|
With proper indenting it would look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
double SalesRep::getcommisions()
{
float commission;
if (salesAmt <= 8000)
commission = .10 * salesAmt
else if (salesAmt >= 4000 && <= 8000)
commission = .07 * salesAmt
else if (salesAmt < 4000)
commission = .10 * salesAmt
else //anything over 4000
commission = 0 * salesAmt
return commission;
}
|
But the compiler will see something like this:
1 2 3 4 5 6 7
|
double SalesRep::getcommisions()
{
float commission;
if(salesAmt<8000)commission=.10*salesAmtelseif(salesAmt>4000&&<=8000)commission=.07*salesAmtelseif(salesAmt<4000)commission=.10*salesAmtelse /*anything over 4000*/commission=0 salesAmtreturn commission;
}
|
I took out all the spaces because the compiler does not care about white space. The point is that this is what the compiler is likely seeing.
Now thinking back to something that you should have already learned the a semi-colon ends a line of with some exceptions like an if statement. Now look back over your code and find what is missing.
All that is left if to figure where "salesAmt" comes from. Does it come into the function as a parameter or should it be defined as a member variable of the class?
Hope that helps,
Andy