Problem with looping

This is a discussion on Problem with looping within the C++ Programming forums, part of the General Programming Boards category; Hello I'm currently creating a guessing game program where the user will be asked to guess the computer generated number. ...

Problem with looping

Hello I'm currently creating a guessing game program where the user will be asked to guess the computer generated number. Once the program is finished, at the end the user will be asked if they want to play again. If the user types "Y or Y" the program will loop and when the user types "n or N" it will not loop. Check out my code below.

I tried what you said about the brackets but the program still doesn't loop. What I really want to happen is that when, for example, I finished the game I then will be asked if I want to play again, once I hit "y or Y" the program should loop. Argh I'm really having a hard time figuring out this thing

I didn't suggested anything about where you should place your brackets. That's your choice

Well, then you should have your game inside a loop. No if I input Yes when your program asks me if I want to play again, then I will jump from line 92 to line 100 (since the conditions on line 94 are both false). Line 100 is the end of main, thus the end of your game.

So, place your game in a do while loop, which will have as condition this

Code:

while(answer != 'N' || answer != 'n');

This way, as long as the user does not input N or n, the code inside the body of the do while I suggest will be executed again. So, if the code is your game, your game will be executed again

I didn't suggested anything about where you should place your brackets. That's your choice

Well, then you should have your game inside a loop. No if I input Yes when your program asks me if I want to play again, then I will jump from line 92 to line 100 (since the conditions on line 94 are both false). Line 100 is the end of main, thus the end of your game.

So, place your game in a do while loop, which will have as condition this

Code:

while(answer != 'N' || answer != 'n');

This way, as long as the user does not input N or n, the code inside the body of the do while I suggest will be executed again. So, if the code is your game, your game will be executed again

I already have a do while statement in my program, I tried to put lines 49 to 99 inside another do while statement but I only got an error I don't have any idea where should I put the do while statement you're telling me. Please help me with this.

I don't feel comfortable giving you the direct solution, but I will make an example that does pretty much what you want to do.

I will create an example, that asks the user to guess a number. He has 3 tries available. If he finds the answer, then we will print "Bravo". If not, we will ask him or her if he or she wants to play again. If not, he will terminate by saying goodbye.
Read the code and the comments and then try to modify your main

I don't feel comfortable giving you the direct solution, but I will make an example that does pretty much what you want to do.

I will create an example, that asks the user to guess a number. He has 3 tries available. If he finds the answer, then we will print "Bravo". If not, we will ask him or her if he or she wants to play again. If not, he will terminate by saying goodbye.
Read the code and the comments and then try to modify your main

What specific software are you using sir? I used Turbo C++ version 3.0 because our professor required us to use it. I believe this version do not support boolean type. I'm totally messed up argh . I got errors in line 1 unable to open include file iostream, line 2 declaration syntax error, line 8 undefined symbol bool and statement missing ";" , line 16 undefined symbol and undefined symbol endl, line 17 undefined symbol cin and in line 20 undefined symbol found and undefined symbol true. Would you please give me the answer sir? I'm trying to fix this program for 7 straight hours and I still can't create a solution for this.

Fair warning: you are using an extremely outdated pre-C++ compiler that does not follow the C++ standard. It will be utterly and completely useless in real life.
So I suggest you complete the course as best you can (there is little you can do about the tools most likely, so...) and the completely forget everything. Every little thing you've learned because it's complete and utter nonsense. The best thing you can do it re-learn C++ from the beginning later if/when you need to use it.

And as for a solution, sorry, not going to happen. You are required to be able to properly code a task yourself. Otherwise, you will not learn anything.
The logic - the flow of code - is something that every programmer must know and master. If there any problems in the code, you need to learn how to use a debugger. That, or make a flowchart to trace the flow of the code (not ideal).

The problem is what Elysia states. I wanted to say that the headers you use are really old, but I wanted first you to complete the program.

What is happening is that your compiler does not recognize what mines does.
But, if using this compiler is a must by your professor, then use your own headers to accomplish this program, but then have a conversation with your professor about all this. The headers you are using are what Elysia said.

So, instead of a boolean variable use an int, and represent false as zero and true as 1.
Example of using an int variable as a boolean one.