I'm trying to take a letter guess from the user. I then want to see if the users guess matches a character in my hidden word. If it does match i want to show the hidden word as asterisks with the matched character revealed.
e.g user guesses - "a"
If hidden word was bat i'd display "*a*"
my code so far:
void userGuess()
{
string userguess;
for (int i = 0; i < getword.length + 1; --i);
cout << "Enter a letter or a guess... ";
cin >> userguess;
if (userguess.length() == 1);
charguess();
else if (userguess == getword);
cout << "Well done!";
//run menu
else
cout << "Wrong!";
JLBorges, out of interest would you write something like this: for( char c : word ) masked += guessed_chars.find(c) == std::string::npos ? '*' : c ;
in production code?
Depends. I generally tend to conform to the existing style conventions of the code-base as a whole.
Unless it is a palooka set up (auto-ident? now what on earth is that? code-review, you say? does it have horns? test-frames? ... etc.) whose religious tenets include: 'if there can be a brace, there must be a brace'.