Thread: A little help in displaying a high value in a loop

1. A little help in displaying a high value in a loop

I've been racking my brain for about 2 hours now, so I decided to ask CProgramming for help. I have a problem I got to do for school and I have basically everything but I can't get one thing.

The problem is I need to make a loop where I keep entering temperatures. I did this by using a do-while. I then end the loop when I enter 999 as a sentinel or flag to stop. So I enter the numbers like this...

Enter temperature: 88
Enter temperature: 66
Enter temperature: 69
Enter temperature: 97
Enter temperature: 57
Enter temperature: 999

So after I did this, I ended the loop. Now I was suppose to find the average temp and the high temp. I did the average temp no problem by doing sum of values devided by how many temperatures, but I have no idea how to get the program to display the 97 as the highest temperature. A little help please. Basically I have everything and I just need to know how it displays the largest number entered in the loop. THat's the only bit of code I need. If you need me to I will post the code I currently have, I'd just have to retype it up on this comp.

2. Also, I would need to do this the most basic way as possible.

3. if ( temp > max_so_far ) max_so_far = temp;

4. Here we go...

Code:
```/* Temperature Program */

#include <iostream.h>

int main()
{
cout << "Temperature Program" << endl;
cout << "===================" << endl;

int Temperature;
int NumberOfTemps = 0;
int SumOfTemps = 0;
const int Sentinel = 999;

cout << "Enter temperature: (" << Sentinel << " to quit): ";
cin >> Temperature;

do
{
SumOfTemps = SumOfTemps + Temperature;
NumberOfTemps = NumberOfTemps + 1;

cout << "Enter temperature: (" << Sentinel << " to quit): ";
cin >> Temperature;
}
while (Temperature != Sentinel);

cout << "Average: " << (SumOfTemps)/(NumberOfTemps) << endl;
cout << "High Temperature: " << endl;
return(0);
}```
If someone can fill that in at the bottom, I would be forever greatful.

5. Nevermind guys, I was playing around with it and got it. If anyone else has the same problem, here is my finished code...

Code:
```/* Temperature Program */

#include <iostream.h>

int main()
{
cout << "Temperature Program" << endl;
cout << "===================" << endl;

int Temperature;
int HighTemp;
int NumberOfTemps = 0;
int SumOfTemps = 0;
const int Sentinel = 999;

cout << "Enter temperature: (" << Sentinel << " to quit): ";
cin >> Temperature;

do
{
SumOfTemps = SumOfTemps + Temperature;
NumberOfTemps = NumberOfTemps + 1;

cout << "Enter temperature: (" << Sentinel << " to quit): ";
cin >> Temperature;

if ((Temperature != 999) && (Temperature > HighTemp))
HighTemp = Temperature;
}
while (Temperature != Sentinel);

cout << "Average: " << (SumOfTemps)/(NumberOfTemps) << endl;
cout << "High Temperature: " << HighTemp << endl;
return(0);
}```