![]() |
|
#1
|
|||
|
|||
Loop not executing, need a code reviewI am having issues with this program executing, as far as I can see there aren't any issues with the structure - which is obviously wrong. There are no errors or warnings when compiled, so I am not sure where to turn. I can not get past the initial input stage, it seems that the while loop is not executing, therefore not printing my output. Hopefully a new pair of eyes on this will help, thanks.
CPP / C++ / C Code:
|
|
#2
|
|||
|
|||
Re: Loop not executing, need a code reviewQuote:
Make the program tell you exactly what it is seeing and what it is working with: CPP / C++ / C Code:
(Stand by to hit ctrl-c.) Regards, Dave |
|
#3
|
|||
|
|||
Re: Loop not executing, need a code reviewI had a loop that was executing in infinity. Now my issue is that I have included break statements for each container size, but this will stop the loop. I have tried to return to the start of the loop, but it didn't seem to change anything. I have also tried to use a 'do' loop and incremently count with a 'for', but that didn't seem to work either. Does the statement 'dooflingy -= 50;' make sense to act like a counter? When executed the container size will increment only once, i.e. 55 is entered the huge size will increment 1, but the medium will not count.
CPP / C++ / C Code:
|
|
#4
|
|||
|
|||
Re: Loop not executing, need a code reviewHere's a clue: What happens inside the loop when dooflingy = 1? Think about what each if statement checks for and you'll see what is happening.
|
|
#5
|
|||
|
|||
Re: Loop not executing, need a code reviewQuote:
Walk through it "by hand". What if you had entered, say, 100? How many times would you go through the loop? You certainly don't want to break out of the loop whenever you find something, right? Now, what if you had entered, say, 40? How many times would you go through the loop? Your structure in the original post was OK. The errors in the details (the comparisons) made it an infinite loop. Fix the comparisons, and all will be OK. Regards, Dave |
|
#6
|
|||
|
|||
Re: Loop not executing, need a code reviewI have found out a problm but i don't know whether it is true or not.
You if statement has some problem. You should changed to a certain range such as CPP / C++ / C Code:
I hope this might help you. __________________
Linux is the best OS in the world. |
|
#7
|
|||
|
|||
Re: Loop not executing, need a code reviewThanks Dave, it was right there in front of me. Always seems like the problem should be harder, but it is the little mistakes that add up.
|
Recent GIDBlog
Last Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Text-Based Roulette Game | mfm1983 | CPP / C++ Forum | 5 | 29-Nov-2006 12:20 |
| How to sort random access file? | wmmccoy0910 | C Programming Language | 12 | 04-Sep-2006 03:40 |
| Here it is again! 35% - 40% off For Life! | my-e-space | Web Hosting Advertisements & Offers | 0 | 20-Apr-2006 14:48 |
| Problem with int mixed with char,... | leitz | CPP / C++ Forum | 17 | 07-Dec-2004 20:56 |
| Segmentation error on executing socket code | nkhambal | C Programming Language | 3 | 30-Aug-2004 12:53 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The