Hey guys I'm trying to figure out how to input the do/while loop so that my program doesn't execute too fast and you wont be able to see the solution. So I read in one of the forums about using a do/while loop so that the program will ask if you want to run it again.
do/while loop
Collapse
X
-
Hmm, that really depends on what your program does. Do-whiles are really good for iterations - sequences, things like that, because you want them to do something while you have something else.
So if you are just doing a simple formula - calculating something that won't change, a do-while would not be ideal, unless you had the condition (the 'do' part) to keep asking if you wanted to wait to show the answer while (the 'while' part) the user would enter no (and then, if they answered yes, you would just exit the loop and print the answer).
So what does your program do? -
Check on the char in the wile loop for y/n will solve ur problem.
pseudo code:
condition = 'n'
do
{process...process...condition = <get char input from keyboard>}
while(condition = 'y')
//This wil solve ur probem (if i understod ur post). else describe ur problem wth some example.Comment
-
Guess you are using one of the IDE's which closes the output window as soon as the program finishes executing.
use getch(); so that the program waits for a user input. that does the trickComment
-
While this is the right idea, it's not the right implementation. Getch() is from the non-standard library conio.h, which is different from system to system, and version to version, meaning it can mess things up if you don't have the exact same version across all systems.Originally posted by Shashi SadasivanGuess you are using one of the IDE's which closes the output window as soon as the program finishes executing.
use getch(); so that the program waits for a user input. that does the trick
A better way would be to, at the end of your program, prompt the user, "Press enter to end program" and then just have any sort of cin or scan() (as you don't mention if you are using C or C++), and just ignore the input values.Comment
-
Are you using Visual Studio.NET???
If so, run your program by selecting Start without Debugging. That will pause the display after the end of main() so you can see what happened.
No need to added gimcracks to your code to pause it.
This selection tells the compiler that you are not using your debugger and therefore do not have any pauses set up.
The other selection is Start. Here, the program just runs and any pauses have to be part of the code.Comment
Comment