I am working on a practice exam right now and I came across a write-your-own code problem that I can't figure out.
The question is:
Modify your first function. In addition to returning the greatest value by pass-by-value, you should also sent a true/false value back to main() if the values are the same. Hint: waht variable type would hold a true/false value? How does this value need to be sent to main?
The first function they speak of is:
double greatest (double value1, double value2){
if (value1 > value2){
return(value1);
}
else {
return(value2);
}
}
Oh, and it can be assumed that all function prototypes were defined earlier.
This is what I have so far for the code we actually need to write for the problem:
double greatest (double value1, double value2, bool tf){
if (value1>value2){
return(value1);
}
else if (value2>value1){
return(value2);
}
if (value1==value2){
tf = true;
return(tf);
}
else {
tf = false;
return(tf);
}
}
I know this is wrong but I just can't figure out what to do for the life of me :(
Any help/hint/explination would be amazing.