(Temperatures) I have the correct output but the test is not passing!


Hello, above is my source code for this given problem.
The goal is to analyze records of temperature to find the closest to zero.

As you can see in the comments, how I was looking to solve the problem is read the data of integers stored in that string variable.

Then, separate them to find a minimum positive number and greatest negative number, then choose the one closest to 0.


You have to use cerr to print debug message.

Then :

  1. You don’t handle positives temps as expected : integers ranging from -273 to **5526**
  2. You don’t output 0 if no temps.

You have to comment your debugs, or use “cerr” instead of “cout” to show them. (debugs: found, pmin, nmax)

And for the last test (0), you have to change your code to check this “special” case.


Hi, I changed to above but still gave me the same error. I think i followed the requirement, and can’t really move forward.

Use cout to print output (and cerr for debug only)

cout << result << endl; //1

Then define your if(n == 0) result 0 outside the loop, because you overwrite result some line after the for-loop…

1 Like

Thanks! It worked now, and output matched.

Now i will move on to fix algorithm for case ‘0’.