| | |
Problem with while loop... probably common
![]() |
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,
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
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)
while(inData) { inData>>temp1; if(temp1>120 || temp1<-30) { cout<<"Error: Temperature must be between -30 & 120 degrees." <<endl <<endl; return 1; } else if (temp1>=120) cout<<setw(72) <<"*" <<endl; else if (temp1>=110) cout<<setw(68) <<"*" <<endl; else if (temp1>=100) cout<<setw(64) <<"*" <<endl; else if (temp1>=90) cout<<setw(60) <<"*" <<endl; else if (temp1>=80) cout<<setw(56) <<"*" <<endl; else if (temp1>=70) cout<<setw(52) <<"*" <<endl; else if (temp1>=60) cout<<setw(48) <<"*" <<endl; else if (temp1>=50) cout<<setw(44) <<"*" <<endl; else if (temp1>=40) cout<<setw(40) <<"*" <<endl; else if (temp1>=30) cout<<setw(36) <<"*" <<endl; else if (temp1>=20) cout<<setw(32) <<"*" <<endl; else if (temp1>=10) cout<<setw(28) <<"*" <<endl; else if (temp1>=0) cout<<setw(24) <<"*" <<endl; else if (temp1>=-10) cout<<setw(20) <<"*" <<endl; else if (temp1>=-20) cout<<setw(16) <<"*" <<endl; else if (temp1>=-30) cout<<setw(12) <<"*" <<endl; }
Thanks Much,
Nate
Behind every great gymnast - is a mentally unstable coach.
![]() |
Similar Threads
- Problem with do-while loop (C++)
- For loop problem (Java)
- problem with do...while loop (C++)
- problem with loop (C++)
- a for loop problem (Java)
- problem with MATLAB loop (Legacy and Other Languages)
Other Threads in the C++ Forum
- Previous Thread: i need a project
- Next Thread: how can i find out some char from string?
| Thread Tools | Search this Thread |
api array based binary bitmap business c++ c/c++ char class classes code codesamplerunwhilecommands coding commentinghelp compile console conversion count decide delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error faq file forms fstream function functions game givemetehcodez graph guess gui hash homeworkhelp homeworkhelper iamthwee ifpug ifstream incrementoperators infinite input int integer java lib linkedlist linker listing loop looping loops map math matrix memory multiple news node output pointer port problem proficiency program programming project python random read recursion reference rpg string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets





