I was wondering if programming a hangman game would be possible. I took a little bit of time to make something, but it doesn't seem to be working very well. Any info is appriciated!
#include <iostream>
using namespace std;
int main()
{
char solution[20]; //holds solution
char blank[20]; //holds "*"'s for unsolved letters
int counter = 0; //general-use counter
int right = 0; //1 = right guess, 0 = wrong guess.
char guess;
cout<<"Enter phrase 20 chars or less."<<endl;
cin.getline(solution, 20);
int puzzLength = strlen(solution); //finds lengtrh of puzzle, stores INT value to puzzlength
//convert puzzle to full uppercase
for (counter = 0; counter < puzzLength; counter++){
solution[counter] = toupper(solution[counter]);
}
//done converting
strcpy_s(blank, solution); //copy solution to the 'blank' array
for (counter = 0; counter < puzzLength; counter++) { //converts characters to *'s to represent blanks
if (isalnum(solution[counter])) blank[counter] = '*';
else blank[counter] = solution[counter];
} //closes for loop
while (solution != blank) { //play game until the 'blank' puzzle becomes the 'right' answer
cout<<endl<<"Solution phrase is: "<<solution<<"."<<endl;
cout<<"The current 'blank' puzzle is: "<<blank<<"."<<endl;
cout<<"Enter a guess."<<endl;
cin>>guess;
guess = toupper(guess);
//cbeck guess!
for (counter = 0; counter <= puzzLength; counter++) {
if (guess == solution[counter]) {
blank[counter] = guess; //fill in the puzzle with the letter
}
} //close loop, done checking guess
} //game is over.
cout<<"Winner!";
cin.get();
return 0;
}