how to implement this for loop that loops through a loop here better (C++)?

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
Your approach is just a little off.

You need only TWO strings:

  • The word(s) to guess
  • The display string with:
     ‣ correctly-guessed letters filled in
     ‣ unguessed letters blank (spaces)

You MAY also want a third string:

  • Incorrectly-guessed letters

When the user enters a letter, you only need to run through the string containing the word(s) to guess to determine what to do.

  • If letter in word(s) to guess: update the display string
  • Otherwise add it to the incorrectly-guessed string and add a body part
    to the hanging man.
  • (You may also wish to consider the case where the user enters a letter
    already guessed correctly. Does this add a body part? Or does the user
    just get reminded that he/she already correctly-guessed the letter.)

Hence:

  • Avoid char *s and C-strings. Use std::string.
  • Make a function to determine if the letter is in the answer string.
  • Make another function to update the display string with the letter.
  • Make yet another function that displays the current display string
    (and incorrect guess string, if you have that) and the current state of
    the hanging man.

The current state of the hanging man should just be a number — the number of body parts added (or remaining) to hang. After each user input, use the above functions and continue or terminate the game depending on whether the user has won (answer string and display string are equal) or lost (no more body parts to hang).

Good luck!
I am a beginner in C++


What resource are you using to learn C++? Apart from cout, that code is very c-ish and not C++. As said by Duthomhas above, use std::string and not c-style char arrays and pointers.

For an on-line resource:
https://www.learncpp.com/

For a book:
Beginning C++20: From Novice to Professional by Ivor Horton
https://smile.amazon.co.uk/Beginning-C-20-Novice-Professional/dp/1484258835/ref=sr_1_15
Topic archived. No new replies allowed.