I wants to input a list of day temperatures and count the number of days with
temperatures above 20 degrees. The C++ program below is supposed to do this and display the result. A temperature of -100 indicates the end of the data.
#include <iostream>
using namespace std;
int main( )
{
float temp;
int nrAbove;
// initialize
nrAbove = 0;
cout << "Temperature of first day (-100 for end of input): ";
cin >> temp;
30
// loop
while (temp > -100)
{
if (temp > 20) // temperature above 20 degrees?
nrAbove++;
} // end of while loop
// results
cout << "Number of days with temperature above 20 degrees C is ";
cout << nrAbove << endl;
return 0;
}
Thanks for taking time to look at this.