problem in finishing the code

hai...im having a problem over here...this is my question.The program will continuously ask the user to enter student’s marks. When a student mark of -1 is entered, the program will display the students with the highest, lowest mark and the average of the class.. i have done the code, but than i dont know how to make the code to show the output for lowest and highest marks.


#include <iostream>

using namespace std;

int main()
{
int n, sum = 0, nums = 0 ;

do
{
cout << "Enter student marks (-1 = quit): ";
cin >> n;

if( n > 0 )
{
sum += n;
++nums;
}

} while( n > 0 );

if( nums > 0 )
cout << "The class average is: " << sum / nums << endl;

else
cout << "No average";



cout << endl;
system("pause");
return 0;
}
Last edited on
Please use the code tags when you post your code.

You will need to add logic that compares each value of n to the lowest value you've seen so far, and likewise for the highest value you've seen so far.
can you give some examples
Add two integers to your code to hold the lowest and the highest, initialize them, and:

If the mark just entered is less than the lowest,
set lowest to the mark just entered

If the marked just entered is greater than the highest,
set highest to the mark just entered
Topic archived. No new replies allowed.