![]() |
|
#1
|
|||
|
|||
coding a sentinel controlled loopThis one is driving me nuts:
I need to code a loop, like a While loop and if a user types -5, the loop will will stop looping. The loop will contain statements which input and output the integers depending on what integer the user types. If either a 2 or a 99 is typed, the integer simply won't be printed. All other integers will be printed. Once the user types in -1, the message, "End of Program" will print. For example; The printf statement will be like "Please enter an integer". If I type in a 8, the message displays, "The integer you have selected is 8". If I type in -5, "End of Program" is printed. If I type in 2, nothing is printed and myabe the message could go back to "Please enter in another integer" or maybe it's better to go back to the original message of "Please enter an integer". Does this make sense? I have tried to code this many and many of times without any success. Any help would greatly be appreciated. Thanks much, Tom |
|
#2
|
|||
|
|||
coding a loopHello Tom,
>I need to code a loop, like a While loop and if a user types -5, the loop will will stop looping. This can be done with the "break;" statement, which allows you to exit a loop you are from any point within that loop. For instance, you may use an if statement and when -5 is encountered the loop breaks. However, you may also keep looping until a -5 is encountered by diong something like this: CPP / C++ / C Code:
>If either a 2 or a 99 is typed, the integer simply won't be printed. This can be controlled through an if statement, with an AND ("&&"): CPP / C++ / C Code:
If this information is not helpful, post what code you do have and I can get back to you. Best of, Pan Thomakos |
|
#3
|
|||
|
|||
|
Thanks for the reply. You were a big help :-) 8-)
|
Recent GIDBlog
More photos on Flickr by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The