473,385 Members | 1,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

do/while loop

4
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.
Jan 21 '08 #1
6 3180
sicarie
4,677 Expert Mod 4TB
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?
Jan 21 '08 #2
alind
7
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.
Jan 21 '08 #3
Tops
4
This is what I'm using

int main()
{
double length;
double width;
double area;

blah ...

blah...


return 0;
}

I don't know if that help at all, I just want the program to have a pause at least before it closes so you can see the solution it comes up with...
Jan 21 '08 #4
Shashi Sadasivan
1,435 Expert 1GB
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 trick
Jan 21 '08 #5
sicarie
4,677 Expert Mod 4TB
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 trick
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.

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.
Jan 21 '08 #6
weaknessforcats
9,208 Expert Mod 8TB
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.
Jan 21 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: JS | last post by:
#include <stdio.h> main(){ int c, i, nwhite, nother; int ndigit; nwhite = nother = 0; for (i = 0; i < 10; ++i)
6
by: John Pass | last post by:
What is the difference between a While and Do While/Loop repetition structure. If they is no difference (as it seems) why do both exist?
7
by: DaVinci | last post by:
I am writing a pong game.but met some problem. the ball function to control the scrolling ball, void ball(int starty,int startx) { int di ,i; int dj,j; di = 1; dj = 1; i = starty;
1
by: pauljturner99 | last post by:
Hi, I'm trying to pass a parameter from a for loop to the nested while loop but only the first counter is passed. Here is the code: dim ctr redim ctr(5) ctr(0) = 2 ctr(1) = 4 ctr(2) = 6
3
by: libsfan01 | last post by:
hi all in my js code i have a while loop contained within a while loop executed on the basis of a conditional if statement, what i want to do is end the entire function on the last execution on...
14
by: Jan Schmidt | last post by:
Hi, in a nested do-while-loop structure I would like to "continue" the outer loop. With goto this should be no problem in while-loops. However, for do-while I cannot get it to work (without a...
6
by: mgcclx | last post by:
For loop and while loop. which one is faster? I see many articles fighting over it and different people come up with different results.
1
by: somenath | last post by:
Hi All, I have doubt regarding how compiler understands about while loop. For example the bellow mentioned code produce the output as mentioned bellow. #include<stdio.h> int main(void) {
3
by: bmerlover | last post by:
I believe my problem lies inside the while loop. When I click the play button on the gui app, it goes inside the while loop, reads the file and calls the necessary function to do what it needs to do....
3
by: numlock00 | last post by:
I have a nested 'while' loop that won't repeat, no matter how many times the outer loop repeats. The outer loop reads through an array of elements; the inner loop Ithe 'while' loop) is supposed to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.