Hangman game validation

I think I am about to shut down completely with validation. Have been working on this hangman game for sometime now and the only validation I can seem to grasp is converting to upper and lower case, =/ Are there any good sites as most seem puzzling.



string player = "";
string wordList[10] = {"string", "variable", "array", "constant", "integer", "character", "comments", "functions", "algorithms", "headers"};
string word = "";
int totalCount = 0;
int attemptCount = 0;
bool wordUsed[10] = {false, false, false, false, false, false, false, false, false, false};
char guess = ' ';
int correctLetters = 0;
bool playAgain();

int _tmain(int argc, _TCHAR* argv[])
{
cout << "\t\t\t~*~*~ Welcome to Hangman ~*~*~";
cout << "\n\nPlease enter your name: ";
cin >> player;
cout << "\n Thank you " << player << "\n\n";
do {
srand(time(NULL));
int temp= (rand()%9);

word = wordList[temp];
wordUsed[temp] = true;

totalCount = attemptCount = word.length() + 10;
cout << "\n You have ";
cout << totalCount--<< "/" << attemptCount;
cout << " chances left.\n";

char tempWord[20] = {'_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_', };

bool correctGuess = false;

for (int counter = 0; counter < word.length() + 10; counter++)
{
for (int i =0; i < word.length(); i++)
{
cout << tempWord[i] << " ";

}
correctLetters = 0;
cout << "Please choose a letter: >";
cin >> guess;
guess = tolower(guess); //converts all case to lowercase
for (int j = 0; j < word.length(); j++ )
{
if (guess == word[j])
{
tempWord[j] = guess;

for (int z = 0; z < word.length(); z++)
{
if(tempWord[z] == word[z])
{
correctLetters++;
}

}

if (word.length() == correctLetters)
{
cout << "\n Congratulations, you guessed " << word << " correctly! \n " ;
correctGuess = true;
break;
}

}

}





if (correctGuess)
{
break;
}

cout << "\n You have ";
cout << totalCount-- << "/" << attemptCount;
cout << " chances left\n";

}
} while(playAgain());

system ("pause");
return 0;
}

(Apologies for the layout)
Hi there,

Please wrap your code in code-tags: [code] code here [/code].
Could you be a bit mroe specific about which other validation you are wanting to do, checking if numbers are entered?

All the best,
NwN
Last edited on
Topic archived. No new replies allowed.