http://pastebin.com/PuqTcaMZ
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.
Hi,
You have to use cerr to print debug message.
Then :
- You donât handle positives temps as expected :
integers ranging from -273 to **5526**
- 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.
2 Likes
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â.