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.
This is from a recent post that is very similar to your program that might help. http://www.cplusplus.com/forum/beginner/248311/#msg1094799 The rest of that post may also be useful and a response from coder777, in a previous message, has a shorter version.
Line 125 The while loop is not necessary just the contents of the loop. Removing the while loop will also eliminate the need for the "goto".
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
i have managed to reset count and managed to get other numbers randomised but and how to clear my array std::fill(guesses, guesses+100, 0); i think it is correct thanks