The homework is to count the number of positive numbers in an array if bool is "true" and count the negative numbers if bool is "false". I am only allowed one loop.
My code will return the positive count correctly but not the negative. what should I fix?
-----------------------------------------------------------------------------
There are many other ways and this is a long-winded one which incorporates the bool variable. You can probably see the this bool variable is unnecessary because the first if condition effectively serves the same purpose.
Way(s) to do this really depend upon what a 'positive' number is classified as. The mathematical definition are numbers greater than 0 (but not equal). However, some classify positive as not negative (negative being less than 0) - which includes 0. What definition is being used here?
@keskiverto
In the above post, your solution 1) doesn't compile with VS2019 - error C2275: 'std::less': illegal use of this type as an expression
[probably because less and greater are different types (they are defined as struct) and the type of op has to be known at compile time?]