Hello, I use the sentinel to control the loops to find the smallest n numbers. However, after I run it, the loops keep running even though I input the Sentinel value. Can someone point out my mistakes. I'm new in programming. Thank you in advance!
test_score is unsigned. So can never have a negative value! When you enter -1 this gets converted into a very large positive number. Change the type of test_score to int (which is signed).
Why are you adding test_score (-1) to sum_score after the loop has terminated? You aren't adding to sum_score inside the loop, so sum_score will be the final value of test_score which is -1.
alright, I understand it much better now, however when I compile and run my program here, I can get the correct sum of score, but when I run it with my compiler, I get the wrong sum of score.