Quote:
|
Originally Posted by Valmont
- The total number of all possible pairs you guessed wrong.
- The algorithm for odd/even products is wrong too but that is closely related on your guesstimation on total possible pairs.
|
I assumed (wrongly?) you shouldn't count pairs of elements with themselves.
Quote:
|
Originally Posted by Valmont
- Resetting variables in that function for re-use is inappropriate since that is not the responsibility of that function. Nor was that part of the task.
However, setting that variable to "0" for reasons of correctness would have been correct. I should have done that to make sure the precondition is right. In your (and mine) case you should have set "ep" to 0 for this very reason.
|
It's not so much about re-use as it is about initialising variables before you modify/read from them. It all comes down to the same thing, really, but I guess I should have formulated it differently.
I didn't set ep to 0 because you never read from it.
Quote:
|
Originally Posted by Valmont
Also this:
Code:
std::size_t i;
for (i = 0; i < size; ++i)
Keep "i" in the scope of the for-loop only. Now it's scope has been extended to the function for no valid reason.
|
I actually knew that

I kinda got used to doing it this way for clarity / compiler portability, since certain dodgy compilers (like MSVC6) extend the scope of "i" to the entire function even if you do declare it within the for-loop.