|
|
|
|
|
|
|
//******************************************************************
// TempStat program
// This program calculates the high and low temperatures
// from 24 hourly temperature readings
//******************************************************************
#include <iostream.h>
#include <limits.h> // For INT_MAX and INT_MIN
const int NUM_HRS =24; // Number of hours in time period
int main()
{
int temperature; // An hourly temperature reading
int high; // Highest temperature so far
int low; // Lowest temperature so far
int hour; // Loop control variable for hours in a day
// Initialize process
high = INT_MIN; // Set high to impossibly low value
low = INT_MAX; // Set low to impossibly high value
// Initialize loop ending condition
hour = 1;
while (hour <= NUM_HRS)
{
// Update process
cin >> temperature;
cout << temperature<< endl;
if (temperature < low) // Lowest temperature so far?
low = temperature;
if (temperature > high) // Highest temperature so far?
high = temperature;
// Update loop ending condition
hour++;
}
// Print high and low temperatures
cout << endl
<High temperature is < high < endl
<Low temperature is < low < endl;
return 0;} |
|
|
|
|
|