Hangman Game: Errors and For loops

Hello guys, I have to make Hangman in C++ and it is going well except I utterly lack the knowledge to make a For loop so I can hide the secret random word. Example:

Program(Hangman) selects random word from array

Random word: Dummy
User would see: *****

And then as the player guesses letters/words the stars would free up so if I were to guess:

User input: M
Random word update: **mm*



I'd be so grateful for any help. I am literally so stuck and really need some advice from experienced c++ programmers.
Last edited on
well first you array word is not inialized correctly seeing as you have a 2 d array but you are trying to stick a whole bunch of chars in the first array. If i were you i would create a string array with only on dimension of variables.

1
2
  string array[3] = {"dude" , "yo" , "hey"};


if you wanted i would take the difficulty and make that the rows for the array if you were set on using a 2d array.
1
2
3
4
string array[difficulty][x] = {"what", "ever"},
                                         {"you" , "want"},
                                         {"here", "dude"};
Last edited on
Hey man thanks for the reply :)

Sadly because it is an assignment I am not allowed to use string.. only Carray (char array is that correct?) which is why I have usedchar words [10][30]. I was told that the first bracket is the max length of the words in the array[10] and then the [30] was the number of words in the char array. Is this correct?

I want to implement difficulties later using switch, but first I need to get the basic program working like getting rid of all these errors and getting my For loop to work.

For clarification, the for loop needs to check what letters entered are correct and then update the hidden word's *'s. I haven't even gotten to the point of making the word *'s yet.

So much to do, seems so complex and errors left right and center.

Thank you for your post mate :)
Hey guys, so I tried to do some debugging last night. Still no luck and still got all those errors.

Some of these errors not even Google seems to know, so they must be really silly errors.


1
2
IntelliSense: no instance of overloaded function "std::basic_istream<_Elem, _Traits>::get [with _Elem=char, _Traits=std::char_traits<char>]" matches the argument list
argument types are: (int)


error C2664: 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::get(_Elem &)' : cannot convert parameter 1 from 'int' to 'char Line 52 Column 1

Like, how am I suppose to know what that means? The random word selector:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 int secretword, secretword_Len,i;
    cout<<"\nSelecting Random Words from dictionary";
    srand ( time(NULL) ); //initialize random seed: 
    secretword = rand() % 30 ; //random number 0 to 29  
    cout<<"\nWord number "<< secretword << " Chosen\n";    
    strcpy(&hiddenword,&words[secretword][i]);
    secretword_Len=strlen(hiddenword[1][20]);
    cout<<"Word length is "<<secretword_Len<<" Letters\n";
    cout<<"\n";
    
	for(i=0;i<secretword_Len;i++)
    {
      cout<<"*";
    }
    cout<<"\n"<<&hiddenword[0]<<"\n";
    cin.get(secretword);
  return 0;


We are suppose to replace the standard words with our own, which I have but it gives me errors in the array areas. Lines and columns in first post.
so this time i looked at your program closer... your types are all char. char is only one character. if you want to put a bunch of chars in an array that can make a string. The max a char can hold is 'p' or 'a' with the single quotes. the c2664 error has to do with that i think
Ah thank you. So must I use a Cstring? How can I do a Cstring.

Like:

string words [bla,bla,bla]

Or similar?

Thanks for the reply jumperkid

Managed to get the array to work as char words but now I get 4 of the same error in different places. Here is the code:

1
2
3
4
srand(time(NULL));
   random = rand()%30;
   strcpy(&*secretword[30],&words[random][0]);
   len =strlen(&*secretword[30]);
Last edited on
Topic archived. No new replies allowed.