Hi i am new here,i am trying to learn c++. I am making a number guessing game, the game check for valid input, if the guess is in range,if the guess allready has been guessed,tells the player if the guess is higher or lower then the randomised number, and gratulate the plyer when the right number has been guessed, there is two other things i am hving troubble with, if the player plays again the number of guesses doesnt reset to zero and the randomised number doesnt change, those two things is what i got stucked on, i have tried to put the srand(time(0)); and int number = rand() % 100 + 1; in the while loop so that runs if the player desides to play again i have written a specified GenNumber function but that did mess upp the code so the structure and logic is important, kind reegards
You have several other problems with your program than just resetting some variables.
Line 44 defines the variable "guess" and line 58 defines the variable "guess". Normally this would be a compiler error, but because of "scope" line 58 is in the scope of the while loop and never sees or used the "guess" defined on line 44. You should do some reading on "scope". http://www.cplusplus.com/doc/tutorial/namespaces/
Avoid using "goto" statements. If the program is done correctly this will not be needed.
Line 120 Did yo mean if (guess == number)? As is you are checking "guess" against it-self and it will always be true.
thanks for the replies, yeah i know that there is things to work on when it comes to the structure, first i am just gonna try to make the program do what i want it to do then i will try to work on that. yeah i will check out the post you linked to thanks