4. Write a function named Exchange that swaps the values of the two double parameters passed and returns the value of the larger of the two parameters. The parameters should be passed by reference.
What I'm wondering is am I suppose to return or swap the variables differently? I really don't quite understand this question at all.
The way I understand the question is Exchange swaps the two numbers first and then returns the larger of the two. So the if statement should be in the Exchange not main()
You need to adjust Exchange() so it returns the larger of the two values, as currently it is returning 0.0 always. The swapping works just fine, you just don't return the larger value.
OK, because num1 and num2 are passed by reference if you cout << both value1 and value2 in main() then you will see they have been swapped.
The next step is Exchange, by your design returns a double and this is where you can return the larger of the two values.
a) in main() declare double largerOrSome Name= Exchange(...)
and
b) in Exchange(...)
leave the swap code as is and put in a bit extra:-
if x is greater than y
then return x
otherwise return y
@TC: It does not "return" the values swapped; yes, the values are swapped, but if you look at line 34 you are returning 0.0. Please note that "returning" a value from a function has a specific, technical meaning, and does not informally refer to what a function does.
Yep, that's ok as far as it goes but you need to go two steps further and 1) use the return value for example by writing double xyz = Exchange(...) with cout << xyz, and also 2) displaying value1 & value2, all in main(). That way you should be able to see what your function has done.