What I suggested was not "cheating".
The code as posted was not correct - you already knew that. Without any background information about (a) where the code originally came from (maybe from a book, or another website, or a college question...) and (b) what the program was supposed to actually do, then my suggestion was a reasonable one.
As for your other comments. yes, you are mostly correct. A function with a type of
void
is explicitly stating that there will be nothing returned from it.
Though this is somewhat overstating things: '
Functions like int, float, functions does return something, has to be called with "cout".'
There is no "has to", you could call the function without any cout at all.
Let's say you have a function like this:
|
int twice(int x) { return 2 * x; }
|
You could correctly do any of these:
or
1 2
|
int result = twice(5);
cout << result;
|
or simply
The last one isn't very useful, but it is valid.
Also finally may I ask, where did the code come from, and what is it supposed to do?