When adding this code to a simple calculator program I receive the error message “Control reaches end of non-void function”.
Now after reading some response I know that I should be adding a return call so that the program doesn’t hang up in the instance that the accumulator is not set but I want to know where to place it or which would be the proper way to phrase this.
Thanks, any help would be appreciated. I can provide the full program code if necessary as well.
-(double) changeSign
{
accumulator = -accumulator;
}
-(double) reciprocal
{
accumulator = 1/accumulator;
}
-(double) xSquared
{
accumulator = accumulator * accumulator;
}
Very simply, each of the methods you have here is declared to return a
double, but you never actually return anything.You need to do something like:
Or, alternatively, if you don’t intend to return the new value of
accumulator, change the return type tovoid:ps. the issue is not that the program will “hang up in the instance that the accumulator is not set”. It’s that you are saying “Here a method that returns a
double“, but the code does not actually return anything. The error message means “I got to the end of this function that you promised would return something, but you seem to have forgotten”.