| | |
Newbie help needed!
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 12
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Apr 2008
Posts: 12
Reputation:
Solved Threads: 0
•
•
•
•
I guess it will always show 0 or 1, because you can only enter 1 input. If you want to get more inputs, you should put this: cin >> temp; inside your while loop. cin >> temp; inside your while loop.[/QUOTE] And i am getting these errors once I compile.
[Warning] In function `int main()':
[Warning] In function `int main()':
Thanks for taking the time to look at my problem.
// How many days with temperature above 20 degrees C?
#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?
cin >> temp;
nrAbove++;
} // end of while loop
// results
cout << "Number of days with temperature above 20 degrees C is ";
cout << nrAbove << endl;
return 0;
}
•
•
Join Date: Apr 2008
Posts: 12
Reputation:
Solved Threads: 0
Thanks people.
Narue
niek_e
Black Magic
It’s working well!
Complete code appears below.
// How many days with temperature above 20 degrees C?
#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?
cin >> temp;
nrAbove++;
} // end of while loop
// results
cout << "Number of days with temperature above 20 degrees C is ";
cout << nrAbove << endl;
return 0;
}
Narue
niek_e
Black Magic
It’s working well!
Complete code appears below.
// How many days with temperature above 20 degrees C?
#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?
cin >> temp;
nrAbove++;
} // end of while loop
// results
cout << "Number of days with temperature above 20 degrees C is ";
cout << nrAbove << endl;
return 0;
}
![]() |
Other Threads in the C++ Forum
- Previous Thread: Pls help...getting text from another window form
- Next Thread: Please help me!! Newbie in C++
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






? 