Newbie help needed!

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Apr 2008
Posts: 12
Reputation: stan.joe1 is an unknown quantity at this point 
Solved Threads: 0
stan.joe1 stan.joe1 is offline Offline
Newbie Poster

Re: Newbie help needed!

 
-1
  #11
Apr 15th, 2008
Originally Posted by niek_e View Post
-remove the ' 30 ' in your code.
-swap lines: cin >> temp; and nrAbove++;
Thanks I was about to post the following.

“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;
}
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 160
Reputation: dmanw100 is on a distinguished road 
Solved Threads: 12
dmanw100's Avatar
dmanw100 dmanw100 is offline Offline
Junior Poster

Re: Newbie help needed!

 
-1
  #12
Apr 15th, 2008
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;
}
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC