By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 950 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

Do While loop

P: n/a
I tried to get cout to view after do while loop but I can't


}while (number != Rand);

cout<< "Got it";
return 0;

the word "Got it" never show.
Please help.
Nov 8 '10 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 5K+
P: 9,197
Put a cout inside your loop and tell me what you see.
Nov 8 '10 #2

Expert 100+
P: 983
It seems to me that there is no action inside the block of your do loop, which changes the state of the computation.

Therefore, the termination condition will never change. Ergo, the loop will execute exactly once, or it will never exit, depending on the values of the variables in the exit condition.

Good luck. Weaknessforcats is _really_ _really_ good. Listen to what she says, and you'll learn a lot.
Nov 8 '10 #3

Jose Diaz
P: 5
First of all

}while (number != Rand);

its going to loop forever (INFINITE LOOP).

The reason cout<< "Got it"; Never showed was because the do-while loop never terminated thus not allowing cout to print message to screen. Put cout<< "Got it"; inside do-while loop. Remember that the message will print forever so make sure you terminate it. In order to terminate it you need to make number equal Rand. (*HINT HINT!) =)
Nov 17 '10 #4

Post your reply

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