I am very new to C++. I am basically self teaching. I came across a Hangman game project that I am using for practice. My problem is to do with the random word generation.
I know that for example int n=rand()% 10
means generate random numbers from range 0 to 10.
Now in the game there is an array with 10 elements for the ten words. What I am confused about is that if numbers from 0 to 10 is randomly generated, that would be a selection from 11 random numbers. However the array only has 10 elements (0-9).
What happens when the random generator chooses 10? Element 10 does not exist in the array, right?
So should this code not have been int n=rand()% 9
instead?
Also, could the same word be repeated before all words have been selected in the game? That would obviously not be ideal. If it could, then how do I prevent this?