944,149 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2948
  • C++ RSS
Oct 31st, 2004
0

Problem with while loop... probably common

Expand Post »
Hi all...

Was wondering if someone could lend a hand - or an eye. I've been trying for hours and was hoping that someone could give me an outside look. I won't beat around the bush, yes this is from a homework assignment, but the assignment is much more than just the loop, and might I add again that I have been working on it for the past couple of days. Here is the loop,
C++ Syntax (Toggle Plain Text)
  1. while(inData)
  2. {
  3. inData>>temp1;
  4.  
  5. if(temp1>120 || temp1<-30)
  6. {
  7. cout<<"Error: Temperature must be between -30 & 120 degrees." <<endl <<endl;
  8. return 1;
  9. }
  10. else if (temp1>=120)
  11. cout<<setw(72) <<"*" <<endl;
  12. else if (temp1>=110)
  13. cout<<setw(68) <<"*" <<endl;
  14. else if (temp1>=100)
  15. cout<<setw(64) <<"*" <<endl;
  16. else if (temp1>=90)
  17. cout<<setw(60) <<"*" <<endl;
  18. else if (temp1>=80)
  19. cout<<setw(56) <<"*" <<endl;
  20. else if (temp1>=70)
  21. cout<<setw(52) <<"*" <<endl;
  22. else if (temp1>=60)
  23. cout<<setw(48) <<"*" <<endl;
  24. else if (temp1>=50)
  25. cout<<setw(44) <<"*" <<endl;
  26. else if (temp1>=40)
  27. cout<<setw(40) <<"*" <<endl;
  28. else if (temp1>=30)
  29. cout<<setw(36) <<"*" <<endl;
  30. else if (temp1>=20)
  31. cout<<setw(32) <<"*" <<endl;
  32. else if (temp1>=10)
  33. cout<<setw(28) <<"*" <<endl;
  34. else if (temp1>=0)
  35. cout<<setw(24) <<"*" <<endl;
  36. else if (temp1>=-10)
  37. cout<<setw(20) <<"*" <<endl;
  38. else if (temp1>=-20)
  39. cout<<setw(16) <<"*" <<endl;
  40. else if (temp1>=-30)
  41. cout<<setw(12) <<"*" <<endl;
  42.  
  43. }
I'm trying to get the loop to stop at the end of the file (inData), but the problem that I run into is that the last temperature(value) in the file gets printed twice.

Thanks Much,
Nate
Similar Threads
Reputation Points: 14
Solved Threads: 1
Light Poster
Coach_Nate is offline Offline
48 posts
since Aug 2004
Oct 31st, 2004
0

Re: Problem with while loop... probably common

Nevermind....
I realized I needed a priming read and put the next read-in to inData at the end of the loop ---- I suddenly feel like a jackass... oh well
Reputation Points: 14
Solved Threads: 1
Light Poster
Coach_Nate is offline Offline
48 posts
since Aug 2004

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: i need a project
Next Thread in C++ Forum Timeline: how can i find out some char from string?





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


Follow us on Twitter


© 2011 DaniWeb® LLC