| | |
Newbie help needed!
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 12
Reputation:
Solved Threads: 0
•
•
•
•
-remove the ' 30 ' in your code.
-swap lines:cin >> temp;andnrAbove++;
“Sorry guys I when I run the program it work’s, when I try again it doesn’t, it sorts of freeze’s.“
Now it works better.
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;
// loop
while (temp > -100)
{
if (temp > 20) // temperature above 20 degrees?
nrAbove++;
cin >> temp;
} // end of while loop
// results
cout << "Number of days with temperature above 20 degrees C is ";
cout << nrAbove << endl;
return 0;
}
Even though its solved here's a solution:
#include <iostream>
using namespace std;
int main()
{
float temp = 0;
int countDays = 0;
while(temp > -100)
{
cout << "Temperature of first day (-100 for end of input): ";
cin >> temp;
if(temp > 20)
{
countDays++;
}
else
{
}
}
cout << "Number of days with temperature above 20 degrees C is " << countDays << endl;
system("PAUSE");
return 0;
}
#include <iostream>
using namespace std;
int main()
{
float temp = 0;
int countDays = 0;
while(temp > -100)
{
cout << "Temperature of first day (-100 for end of input): ";
cin >> temp;
if(temp > 20)
{
countDays++;
}
else
{
}
}
cout << "Number of days with temperature above 20 degrees C is " << countDays << endl;
system("PAUSE");
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 |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





