hangman game direction?

Hi, everyone, this is my first time posting here, so I apologize if I get the formatting completely wrong.

I have to write the hangman game for a homework assignment, however, I am so confused and feel lost. Any kind of hint/direction would be much, much appreciated

Anyways, here's my 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <string>
#include <iomanip>
#include <time.h>
#include <vector>
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::vector;

void startMenu()
{
    cout << "Welcome to hangman!" << endl;
}

string wordSelection()
{
    srand(static_cast<unsigned int>(time(NULL)));
    const string wordSelection[10] = {"HELLO WORLD", "APPLE", "PEACH", "FUN", "SUNNY",
    "GREY", "COMPUTER", "BED", "SOFA", "PHONE"};
    string randomWord = wordSelection[rand() % 10];
    
    return randomWord;
}

void replaceHyphen(string& word)
{
    for (int i=0; i<word.length(); i++)
    {
        if (word[i] !=' ') word[i]='-';
    }
    cout << "Here's your string: " << word << endl;
}

char inputLetter()
{
    char letter;
    cout << "Please enter your letter: ";
    cin.get(letter);
    
    
    return letter;
}

void lettersGuessed(char letter)
{
    vector<char> lettersGuessed;
   
    lettersGuessed.push_back(letter);

    for (int i = 0; i < lettersGuessed.size(); i++)
    {
        cout << "Letters guessed so far: " << lettersGuessed[i] << ", " << endl;
    }
}

void letterCheck(char letter, string randomWord)
{
    unsigned long length = randomWord.length();
    for (int i = 0; i < length; i++)
    {
        if (randomWord[i] == letter)
        {
            randomWord[i] = letter;
            cout << randomWord;
        }
    }
}

int main()
{
    startMenu();
    string randomWord = wordSelection();
    replaceHyphen(randomWord);
    char letter = inputLetter();
    letterCheck(letter, randomWord);
    return 0;
}


Thanks a lot!
As you can see, this is only half of what I should have, I don't really know what to do next. I have to check to see if the letter is in the string, if no, then I have to loop back to get the input from the user. If yes, then I have to replace the hidden part with the letter, output the string with the replaced word, and check to see if all letters are guessed. Then if no, I have to loop back to getting input again.
Last edited on
I think you should first forget about the code and write down in plain English or pseudo code how the game should be played. Once you have done this it's normally not soo difficult to write the code.
Last edited on
Topic archived. No new replies allowed.