We help IT Professionals succeed at work.

Help with guess letter location.

jschmuff
jschmuff asked
on
238 Views
Last Modified: 2010-04-21
I have my hangman game all done and plays great, but I have a small problem. Where the blanks spaces I have '_' and it works great but my whole game is all \t so it is somewhat centered and the blank spaces where I guess are all on the left with no indent how can I get these centered to? or at least tabbed over?
I have tried using \t in there or something doesn't seem to work!

Here is my portion of code in HGame.cpp code:
void HGame::playGame()
{
	char Continue = 'Y';
 
	cout << "\t\tWelcome to Hangman!" << endl;
 
	while(Continue == 'Y')
	{
		myGame.runGame();	
		cout << "\n\tDo you want to play again? (Y or N): ";
		cin >> Continue;
		Continue = toupper(Continue);
	}
 
	cout << "\n\tThanks for playing." << endl;
}
void HGame::runGame()
{
	myGame.loadList();
 
	int word;
	int condition = 1;
	int blanks = 0;
	char Guess[MAX_WORD_SZ];
	char Copy[MAX_WORD_SZ];
	char Letter;
	int Correct = 0;
 
	srand((unsigned)time(NULL));
	word = rand() % count;
 
	strcpy_s(Copy,List[word]);
 
	Sz = strlen(List[word]);
 
	for(; blanks < Sz; blanks++)
	{
		Guess[blanks] = '_';
	}
 
	Guess[blanks] = '\0';
 
	while(condition != 6)
	{
		myGame.hangMan(condition);
		cout << Guess << endl;
 
		cout << "\tGuess letter: ";
		cin >> Letter;
		cout << endl;
		Letter = tolower(Letter);
 
		for(blanks = 0; blanks < Sz; blanks++)
		{
			if(Copy[blanks] == Letter)
			{
				Guess[blanks] = Letter;
				Correct = 1;
				cout << "\n\tGood Guess...";
 
				if(strcmp(List[word],Guess) == 0)
				{
					cout << "\n\tThe word was: " << List[word] << endl;
					cout << "\n\tYou have won and did not hang... good job!\n";
					return;
				}
			}
		}
 
		if(Correct == 0)
		{
			cout << "\n\tBad guess, try again...\n";
			condition++;
		}
 
		Correct = 0;
	}
 
	myGame.hangMan(condition);
	cout << "\tThe word was: " << List[word] << endl;
 
}

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
                (hangman graphics)
_______
                guess:

the _______ I would like tabbed over

the code for that is on line 36-39
evilrixSenior Software Engineer (Avast)
CERTIFIED EXPERT

Commented:
Have you tried changing line 46 to output tabs before Guess? Something like: -

cout << "\t" << Guess << endl
CERTIFIED EXPERT
Top Expert 2009

Commented:
>> cout << "\t" << Guess << endl

Yep, that's what I suggested too ... Have you tried that, jschmuff ?

Author

Commented:
Thanks sorry I was confused about what you were talking about.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.