I need to make a handman game I have code but it won't show all the gesses at once and it won't end even if you get it right.
This is what I have

#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

	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 (strcmp(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;
		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.

	return 0;


You stole the code directly from this thread :yawn:

I need to make a handman game

A handman? That's sounds a bit.. ehm.. :)

On second thought:
To solve your problem, put this: strcpy_s(blank, solution); right after

for (counter = 0; counter < puzzLength; counter++)
solution[counter] = toupper(solution[counter]);

That way you all have the same (working) code and your teacher will fail you for sure ;)

This article has been dead for over six months. Start a new discussion instead.