I do not know how I would go about initialising nrAbove in order to display a correct output?? Which would be displaying all the temperatures above 20 degrees c? Pls help
#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;
// Loop
while (temp > -100)
{
cout << "Enter the next temperature: ";
cin >> temp;
}
if (temp > 20)
{
nrAbove++;
}
// Results
cout << "Number of days with temperature above 20 degrees c is " << nrAbove << endl;
#include <iostream>
usingnamespace std;
int main( )
{
float temp = 0.0;
int nrAbove = 0;
cout << "Temperature of first day (-100 for end of input): ";
cin >> temp;
// Loop
while (temp > -100)
{
cout << "Enter the next temperature: ";
cin >> temp;
//check for days above 20 has been moved inside the while loop
// to check each time a new value is added.
if (temp > 20)
{
nrAbove++;
}
}
// Results
cout << "Number of days with temperature above 20 degrees c is " << nrAbove << endl;
return 0;
}
well initialization can be done at the beginning....in the declaration part as well....n for the incorrect output....i can see that the if-condition should be placed inside the while loop!!!!