problem with while loops

hi im relatively new to c++ coding but wrote a program that is supposed to ask the user for a number between 0 and 500. The program generates a random number as well and tells the user if their guess is higher or lower than the random variable.

For this i used two loops beginning with while, and they do work but when i run the program sometimes after a number of guesses it randomly returns itself to 0. could anyone suggest any reasons why??
If we had the code to look at we could help you. Without it all we can offer is a shot in the dark.
This is just a basic guessing game .
You can even look for it just by googling it .

1
2
3
4
5
//Seed the random only once
srand((unsigned)time(0)); 

//for a fixed number, dont put it within any loop? 
int random_integer = rand(); 


However, that would help with your code posted up here
Hi guys , i m a beginner in c++ , i was trying to create a simple program that prints any random line for infinity times without interruption .. but it has to abort if the user wants ,say ( he can press any key to abort).

I tried the program like this
1
2
3
4
5
6
for(;;)
{
  cout<<"hello";
  cin>>ch;
  if(ch=='y')break;
}  


i encounter a problem that the program was stopping to take an i/p every time it get into the loop.... that is undesireable .....
plz help me out to solve this problem....

I would expect that i would get solution very soon
Last edited on
Topic archived. No new replies allowed.