logical error

hi this program compile and run correctly but it gives wrong out put, please help..

// calculate the number of days with temp greater than 20 degrees.
#include <iostream>
using namespace std;

int main ()
{
int nrAbove ;
int temp ;
bool result;
nrAbove = 0;
temp = 0;
cout <<"Temperature of first day (-100 for end of input) : ";
cin >> temp;
while (temp > -100)
{
cout <<"Temperature of next day (-100 for end of input) : ";
cin >> temp;
result = temp > 20;
if (result)
temp += nrAbove;
nrAbove++;
}
cout << "Number of days with temperature above 20 degrees C is ";
cout << nrAbove << endl;

return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;

int main ()
{
int nrAbove ;
int temp ;
bool result;
nrAbove = 0;
temp = 0;
cout <<"Temperature of first day (-100 for end of input) : ";
cin >> temp;
if (temp>20) nrAbove++;
while (temp > -100)
{
cout <<"Temperature of next day (-100 for end of input) : ";
cin >> temp;
result = temp > 20;
if (result) nrAbove++;
}
cout << "Number of days with temperature above 20 degrees C is ";
cout << nrAbove << endl;
return 0;
}
Thank you very much, i've been trying to solve this problem for the pass four days. thanx u the star.
Topic archived. No new replies allowed.