943,691 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1232
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Apr 15th, 2008
-1

Re: Newbie help needed!

Click to Expand / Collapse  Quote originally posted by niek_e ...
-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;
}
Reputation Points: 7
Solved Threads: 0
Newbie Poster
stan.joe1 is offline Offline
12 posts
since Apr 2008
Apr 15th, 2008
-1

Re: Newbie help needed!

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;
}
Reputation Points: 104
Solved Threads: 27
Posting Whiz in Training
dmanw100 is offline Offline
239 posts
since Apr 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Pls help...getting text from another window form
Next Thread in C++ Forum Timeline: Please help me!! Newbie in C++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC