![]() |
| ||
| where is my infinite loop coming from? this is what my program looks like but after prompting and reading my files, i get an infinite loop. the program compiles and i just put that simple cout statement just to see if anything will come out. can anyone see where i am messing up within my main that is causing this infinite loop?
|
| ||
| Re: where is my infinite loop coming from? line 87: array elements are numberd from 0 to but not includeing the number of elements in the array. So that loop should be coded like this: for (int hw_c = 0; hw_c < MAX_HW; hw_c ++) line 89: that's initializing the wrong array. It should be initialzing array hw. I'll need the two text file in order to actually test your code. |
| ||
| Re: where is my infinite loop coming from? The best way (I find) of troubleshooting is to just stick a whole bunch of print statements in your code ( printf()...or I guess you could use cout no difference). If you stick specific print statements before and after each loop, you can tell whether your program made it to that point or not. This way, you can isolate whatever loop is the problem and work from there. Note that, though your code may enter an infinite loop, the problem may lie in previous code...so keep a sharp eye out! (Note: I always think it best to force you to think about the problem rather than just giving you a straight up answer. Fact is, every1 runs into these problems, no matter how experienced a programmer you are. So its could practice to learn to troubleshoot your own code. That said, I also didn't bother to analyze your code...thought it would take too long. So this way, its a win win situation -- you learn to troubleshoot, and I don't need to figure out what you are doing in your program ;) But if you still need help, post back and I, or someone else, will take a closer look...) EDIT: apparently somebody else has already replied, so nvm :P |
| ||
| Re: where is my infinite loop coming from? this is what my data looks like studentinfo 567 white robert 43 blackburn donna 722 Grey jAMes 19 bRoWn jAnE gradeinfo 722 E 1 95 E 2 89 E 3 90 Q 567 E 1 67 H 1 20 H 5 20 E 2 76 Q 83 this line should be ignored, 83 is not a valid ID# 19 H 1 20 H 2 20 H 3 19 H 4 18 H 5 16 Q 43 E 3 91 Q 19 H 6 20 H 7 20 H 8 20 H 9 20 H 10 18 Q 722 H 5 20 H 6 20 H 7 20 Q 19 E 1 85 E 2 90 Q 567 E 3 80 Q 722 H 4 15 H 3 14 H 2 20 H 1 20 Q |
| ||
| Re: where is my infinite loop coming from? i have adjusted all my loops accordingly and i fixed that array but i'm still getting the infinite loop after i prompt and read in my output file |
| ||
| Re: where is my infinite loop coming from? The infinit loop is here: for (int hw_r = 0; hw_r < n; n ++) That should be hw_r++, not n++. That's an easy mistake to make, I think we have all done that at one time or another. |
| ||
| Re: where is my infinite loop coming from? thank you. i just saw it also. there was minore tweakings i had to do through the prog too but i think i'm on the right track now. fingers crossed |
| ||
| Re: where is my infinite loop coming from? Quote:
|
| ||
| Re: where is my infinite loop coming from? The loops that read the data are also coded wrong -- there is no need for using eof() at the top of the loop. Here is a better and more accurate way to code those loops while(n < MAX && inf1 >> names[n].id >> names[n].lname >> names[n].fname) |
| All times are GMT -4. The time now is 2:01 am. |
Forum system based on vBulletin Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
©2003 - 2010 DaniWeb® LLC