Say the word to be guessed is named wtbg.
guessed_chars_so_far = 0;
while (guessed_chars_so_far < strlen (wtbg)) {
boolean guessed = false;
while (guessed == false) {
cout << "Guess character in position " << guessed_chars_so_far << endl;
cin >> c;
if (c == wtbg[guessed_chars_so_far]) {
cout << "Correct !" << endl;
guessed = true;
guessed_chars_so_far ++;
}
else {
cout << "Wrong guess, let's try again " << endl;
}
}
}
To answer your question, to compare two characters you don't need strcmp, you can simply compare them (with ==). If you want to compare two strings, you need to use strcmp.
edit: even though my code was indented, the board ignores that...
Bookmarks