Hangman c++. No errors but strange output.

Trying to make a hangman game that replaces the dashes with the correct letter once guessed using parallel arrays. I've spent hours trying to put this together. I receive no errors when I build, however, my output is this,

0x6efd70Please guess a letter: b
ox6efd70
Please guess a letter:

Obviously somewhere in my logic I have an error but I cannot find it.





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
#include <iostream>
using namespace std;

void the_menu(string da_blank[6], string the_guess){

    cout << da_blank;
    cout << "Please guess a letter: ";
    cin >> the_guess;

    return;
}



void guess_checker(string DA_WORD[], string da_blank[], string the_guess, int SIZE, int count_correct, int sub){

    sub = 0;
    while(sub < SIZE){

        if(DA_WORD[sub] == the_guess){
            count_correct = count_correct + 1;
            da_blank[sub] = the_guess;
        }
        sub = sub + 1;
    }

    cout << da_blank << endl;

    if(count_correct != SIZE){
        cout << "Please guess a letter: " << endl;
        cin >> the_guess;
    }
    return;
}



void end_game(string da_blank[6]){
    cout << "You guessed the word!" << endl;
    cout << da_blank;

    return;
}



int main()
{
    int sub = 0;
    int count_correct = 0;
    string the_guess;

    const int SIZE = 6;
    string DA_WORD[SIZE] = {"b","a","n","a","n","a"};
    string da_blank[SIZE] = {"-","-","-","-","-","-"};

    the_menu(da_blank, the_guess);

    while(count_correct != SIZE){
        guess_checker(DA_WORD, da_blank, the_guess, SIZE, count_correct, sub);
    }

    end_game(da_blank);

    return 0;


}

You can't just cout an entire array. You need to use a loop to cout each array element separately. You'll probably want to pass the size of the array to the function as well, since presumably it won't always be 6.
I think you missunderstood the way to use a string.

 
string DA_WORD[SIZE] = {"b","a","n","a","n","a"};


This is not a string, but an array of six string. If you want to initialize a string, do this :
string str="blablabla";

With this one you don't need to get a constant size and you can use string::size().

By the way you can declare "DA_WORD" as "const" here.
Topic archived. No new replies allowed.