Errors in random word selector

Hey guys, I am getting a megaton of errors in this code segment and I cannot figure it out. I will just link the segment of code with the errors as well as the error list. Thanks. These segment of code is used to selecting a random word from char words 2D array (We have to use a 2D array) and then storing it in secretword.


Error list:

warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data. Line 39 Column 1

warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS Line 42 Column 1

error C2109: subscript requires array or pointer type Line 43 Column 1

error C2109: subscript requires array or pointer type Line 51 Column 1

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

error C2065: 'i' : undeclared identifier Line 78 column 1

error C2143: syntax error : missing ')' before ';' Line 78 column 1

error C1903: unable to recover from previous error(s); stopping compilation Line 78 1

IntelliSense: expression must have pointer-to-object type Line 43 column 38

IntelliSense: expression must have pointer-to-object type Line 51 column 29

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)
No line or column

Last edited on
post the whole code please.
in case this is the whole code, you dont even have a main()
Whole code:

There ya go
Last edited on
Part of the error is the way you are bracing your code I believe. The brace at line 35, what is it there for? Line 53, you return 0. Your program ends there. Nothing after that will run in your program. Also, the while at line 78 has no braces except at the end at line 86 (which I think is supposed to be the close brace for main(). It's hard to tell though with your indentation/bracing style.) Also, the if inside the while has no braces at all. Any block of code inside any kind of loop must be enclosed by braces if it contains more then 1 statement.

There are a bunch of errors inside the while itself. First, the test expression for a while loop can only contain 1 statement or expression. What you wrote looks like it belongs in a regular for loop. While loops should only have a test expression in the parentheses. And loops do not require semi-colons after the parentheses. This mistake also applies to the if loop. Finally, inside the if, you are trying to index a char variable. Only arrays (and certain other containers) can be indexed like that. And last, line 84 is comparing displayword to the length of secretword[i]. This is simply wrong for several reasons, first being like I said before, you are trying to index a variable, not an array. Second being the length of a char variable is 1 since it can only hold 1 character. Third, comparing the two does nothing in this context (like it does in the test expression of the if loop.)
Last edited on
line 43 hiddenworld is no array, it's a char. maybe using a char array and using only 1 dimension, was your plan there, i dont know. line 51 deals with the same problem.

line 52 you try to read the users input into a integer, that will not work. use char or string.

line 78 i is not declared, that means it's missing an int, but the while function wont work anyways. guess you just mixed it up with a for loop.

line 78 again, remove the ";"

thats all my compiler can do so far. fix it and post again
What I am trying to do with the while is compare displayword & secretword so that displayword will be the same character/letter length as the secret word the player has to guess. I am making Hangman.

I am sorry, new to c++. I do not know how to structure properly.

Btw, when asking questions regarding errors should I post the error list or do you guys generally run the code in your own IDEs and see them yourself?

Thanks A LOT guys! Here is the updated code:

Last edited on
Topic archived. No new replies allowed.