cout<<endl<<"The average test score is "<<average<<endl;
system("PAUSE");
}
I am trying to find the highest, lowest and average in this array. I can get the average, but I am not sure how to get it to pull the highest and lowest values that are entered.
keep comparing them with testScore[a] to see if they are the lowest or highest numbers.
I hope this helps, without giving away too much information.
I think it would be better to compare the minimum and maximum in the WHILE loop instead of the FOR loop, as suggested above, though either is doable. Assuming you do it in the While loop, here's some revised code that can get you on the right track:
int minimum = testScore[testNum]; // initialize to first score.
int maximum = testScore[testNum]; // initialize to first score.
while(testNum < TESTS && testScore[testNum])
{
total += testScore[testNum];
++testNum;
if(testNum < TESTS)
{
cout<<"Enter a score: ";
cin>>testScore[testNum];
if(/* compare testScore[testNum] to minimum */)
{
minimum = testScore[testNum];
}
if(/* compare testScore[testNum] to maximum */)
{
maximum = testScore[testNum];
}
}
}
cout<< "The entered test scores are: ";
for(a = 0; a < testNum; ++a)
cout<<testScore[a]<<" ";
average = total / testNum;
cout<<endl<<"The average test score is "<<average<<endl;
// display maximum and minimum.
system("PAUSE");
}
See lines 19, 20, 32 - 39, and 49, which I have added. Line 49 is a simple cout statement. Look at lines 32 and 36. You need to test for the appropriate conditions and fill that in where the comment is.
Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
This thread is more than three months old
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.