problem in finishing the code

Jul 17, 2012 at 7:46pm
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 Jul 17, 2012 at 7:47pm
Jul 17, 2012 at 8:10pm
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.
Jul 17, 2012 at 8:35pm
can you give some examples
Jul 18, 2012 at 12:49pm
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.