Hello there! This is my first post so I'd like to say hello to everyone on the forums!
Anyway, I am coding a hangman game. I read my words from a text file with ifstream, then I randomize a word and I set the string "sSelectedWord" to the randomized word.
After that I get user input
cin >> sGuess
and I set a for loop up to check if sGuess is the same as any letter in sSelectedWord
sGuess == sSelectedWord[i]
Where i is the sSelectedWord.length
But I have no idea how to compare the entered "sGuess" with "sSelectedWord"
Hopefully it makes enough sense for anyone to understand and be able to help.
In a nutshell the question would be "How do I compare "cin >> sGuess" with "sSelectedWord""
I remember doing this somehow but I don't remember how and I lost the code...
EDIT: Dave Sinkula told me to just post the code so:
void mainSPGameFunc() {
readFileGetRandom();
string sSelectedWord = readFileGetRandom();
string sGuess;
int iWordLength = sSelectedWord.length();
cout << "Guess the word!\n";
for(int i = 0; i < iWordLength; i++) {
cout << "_ ";
}
cin >> sGuess;
[B]for(int i = 0; i < iWordLength; i++) {
if(sGuess == sSelectedWord[i]) {
cout << "RIGHT!";
}
system("PAUSE");
}[/B]
}
Cut down to the parts I needed help with. I put the code where I try to compare the strings with bold tags