You are here:

C++/Calculating highest and lowest test scores without arrays.


I am to input data that looks like this, with the negative numbers dividing the sections:
I am to calculate the highest,lowest for each section.  My problem is trying to find out how to get the lowest and highest grade for each section.

Doing this kind of program without using arrays is a bit of a pain, but still easily done. The first thing you need to do is create two variables: grade_highest and grade_lowest. Then read in the first number, and set both grade_highest and grade_lowest equal to that value. Being the first number in the list, it is both the highest and lowest grade. The next step will be to look at the next number. If it's higher than the highest grade, reset grade_highest to the new number. If it's lower than the lowest grade, reset grade_lowest to the new number. If, however, the number is less than 0 you'll want to print out onto the screen the current values of grade_highest and grade_lowest, then set both of their value equal to zero. This will make sure that the program is not going to compare the values from the previous section with the new section. You're going to have to use a series of 'if' statements, with the first 'if' statement checking to see if the value of the number is less than zero. If the number isn't less than zero, you'll have some more 'if' statements nested within the 'else' portion of the 'if' statement. It seems kinda complicated, but it's not bad at all. If you have any further questions, please let me know.

Best Of Luck,


All Answers

Answers by Expert:

Ask Experts


Alan F.


Having problems with any basic or intermediate parts of C++? I can answer those questions for you using simple English. I have been taking C++ in school for a couple years, so I still remember what it was like to be a beginner (especially with C++, which is a difficult language)!


I have a C++ web page that discuses the basics of C++. The address is:

©2017 All rights reserved.