Hello, I am a beginner in C++ and I am making a simple hangman game.
While making the text writer, I ran into some problems. I spent around 3 hours just on this small problem, so I want to share this with you guys so that you can help me win against this headache that I have. Thanks
Here is the code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
void refreshType(char saved[26]){
char draw[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char *pDraw = &draw[0];
int Start;
Start = 0;
int End;
End = 26;
int i = 0;
while(Start != End){
for(i = 0; i < 26; i++){
if(saved[i] == *pDraw){
std::cout << "/ " << std::flush;
std::cout << "\nsaved[i]: " << saved[i] << std::endl;
pDraw++;
Start++;
} else if(saved[i] == *pDraw){
std::cout << *pDraw << " " << std::flush;
pDraw++;
Start++;
}
}
}
}
|
Now I will give an explanation to what this does...
I:
in the function parameters we have `char saved[26]`, this contains all the letters that are guessed by the user(the player).
II:
inside the function:
we have `char draw[26]`, this contains the letters that are to be printed on the console(basically the alphabet)
we have `char *pDraw = &draw[0];` which acts as an index for the char array(draw).
we have `Start = 0` and `end = 26`, these are the parameters for the while loop condition.
we have `int i = 0` which is the index for the for loop.
III:
the loops: the while loop will act as the index for the draw loop.
and the for loop will act as the loop that runs through the saved array and checks if the letter guessed is in there or not.
Thats it. now, What I Want!!!
1. a loop that runs through the draw array and cout letters
2. a loop that: for every iteration of the draw loop it will check if the letter is equal to the letter guessed that is stored in the saved array.
3. if it is then output "/" instead of the letter.
4. if its not, then output the letter that is in the draw loop.
thank you very much for your patience everyone. i know i wrote a lot