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.
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.
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.
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