Problem with while loop... probably common

Reply

Join Date: Aug 2004
Posts: 48
Reputation: Coach_Nate is an unknown quantity at this point 
Solved Threads: 0
Coach_Nate's Avatar
Coach_Nate Coach_Nate is offline Offline
Light Poster

Problem with while loop... probably common

 
0
  #1
Oct 31st, 2004
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,
  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
Behind every great gymnast - is a mentally unstable coach.
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 48
Reputation: Coach_Nate is an unknown quantity at this point 
Solved Threads: 0
Coach_Nate's Avatar
Coach_Nate Coach_Nate is offline Offline
Light Poster

Re: Problem with while loop... probably common

 
0
  #2
Oct 31st, 2004
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
Behind every great gymnast - is a mentally unstable coach.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC