Click here to Skip to main content
15,900,482 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generalhelp Pin
gentleguy27-Jan-08 15:47
gentleguy27-Jan-08 15:47 
GeneralRe: help Pin
Luc Pattyn27-Jan-08 16:23
sitebuilderLuc Pattyn27-Jan-08 16:23 
GeneralRe: help Pin
Cranky27-Jan-08 22:36
Cranky27-Jan-08 22:36 
QuestionPrinting text fields onto a form Pin
Henri27-Jan-08 13:36
Henri27-Jan-08 13:36 
GeneralRe: Printing text fields onto a form Pin
Mark Salsbery27-Jan-08 13:55
Mark Salsbery27-Jan-08 13:55 
GeneralRe: Printing text fields onto a form Pin
Nitheesh George27-Jan-08 17:33
Nitheesh George27-Jan-08 17:33 
GeneralRe: Printing text fields onto a form Pin
Henri6-Feb-08 5:30
Henri6-Feb-08 5:30 
Questionneed a lil help with hang man program Pin
Flash042927-Jan-08 13:29
Flash042927-Jan-08 13:29 
this is my code for a simple hangman game:

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

void main()
{
	string response; //"yes or "no" input from user

	int w=0; //index of the current word

	const int WORDS=4; //number of words

	//loop will construct all nessesary variables and then begin game

	do
	{
		const char body[] = "o/|\\|/\\"; //body parts

		string words[WORDS] = {"MACAW", "SADDLE", "TOASTER", "XENOCIDE"};

		string xword(words[w].length(), '?'); //masked display

		string::iterator i;

		string::iterator ix = xword.begin();
		char letters[26] = {'\0'}; //letters

		int n=0;

		int xcount = xword.length();

		bool found = false;
		bool solved = false;
		bool hung = false;

		int offset = 0;

		int bodycount = -1;

		cout << "guess the word:"; 
		
		//display the word in x's

		for(unsigned loop = 0; loop < words[w].length(); loop++)
			cout << "X";

		//loop to begin game

		do
		{
			cout << "\n\nGuess a letter (case does not matter): " << xword << "\n? ";

			char temp;

			cin >> temp; //letter guess

			if (!isalpha(temp)) //validate for letters
			{
				cout << "\n LETTERS ONLY PLEASE\n";
				continue;
			}

			letters[n] = toupper(temp); //convert to uppercase

			i = words[w].begin(); //initiate iterator to beginning

			found = false; //assume letter is not found in word

			offset = 0; //initial position set to 0

			//replace letter in masked string in all the necessary places, decrement count of characters masked
			//such that we know wen it is solved

			while (i != words[w].end())
			{
				if (*i == letters[n])
				{
					*(ix + offset) = *i;

					found = true;

					if (--xcount == 0)
						solved = true;
				} //end if

				i++;

				offset++;
			}//end while

			if (!found) //if letter was not found
				bodycount++; //increment our count of incorrect guesses

			bool newline = false;

			// graphically draw pieces of the body based upon the number of incorrect answers.

			for(int q = 0; q <= bodycount; q++)
			{
				switch (q)
				{
				case 0:
					cout << " ";
					break;
				case 1:
				case 4:
				case 5:
					newline = true;
					break;
				case 6:
					cout << " ";
					newline = false;
					break;
				case 7:
					newline = true;
					cout << " ";
					break;
				default:
					newline = false;
				}
				

				if (newline)
					cout << "\n";

				if (q == 4)
					cout << " ";

				cout << body[q];

				//if (newline)
				//	cout << "\n";

			}

			//test to see if guesses exceeded
			if (bodycount == 7)
			{
				cout << "\n\n...GAMEOVER...\n";
				hung = true;
				break;
			}// end if

			cout << "\nyour guesses\n";

			//display guesses

			for (int k = 0; k <= n; k++)
				cout << setw(2) << letters[k];
			n++;

		}while(!solved); // end of do while

		cout << "\n\nword: " << words[w] << "\n\n ";

		if (!hung)
			cout << "\ncongradulations!! you guessed my word " << "my word:\n";

		//if we are out of words, then time to exit loop

		if (w++ >= WORDS)
			break;

		//prompt user if they want to play again

		cout << "play again (yes | no)? ";

		cin >> response;

		}while(!response.compare("yes")); //end of do while

		cout << "\nThank You for Playing Hangman" << endl;
}// end of main





Confused | :confused: i am haveing a prob when guessing a letter if u guess a letter correctly and then guess the same letter again then it runs it as if u guessed a diff letter correctly so a user could just guess the same letter for the length of the word and wind up winning with out even guessing ne other letter and i was wondering how to fix thisConfused | :confused:

One love

modified on Sunday, January 27, 2008 8:54:54 PM

GeneralRe: need a lil help with hang man program Pin
Iain Clarke, Warrior Programmer27-Jan-08 23:55
Iain Clarke, Warrior Programmer27-Jan-08 23:55 
QuestionHow to prevent the list box of the combo box appear when catching the CBN_DROPDOWN message? Pin
Francisco José Sen del Prado27-Jan-08 13:29
Francisco José Sen del Prado27-Jan-08 13:29 
GeneralRe: How to prevent the list box of the combo box appear when catching the CBN_DROPDOWN message? Pin
Nitheesh George27-Jan-08 17:42
Nitheesh George27-Jan-08 17:42 
GeneralRe: How to prevent the list box of the combo box appear when catching the CBN_DROPDOWN message? Pin
Hamid_RT27-Jan-08 20:45
Hamid_RT27-Jan-08 20:45 
GeneralRe: How to prevent the list box of the combo box appear when catching the CBN_DROPDOWN message? Pin
Francisco José Sen del Prado27-Jan-08 20:50
Francisco José Sen del Prado27-Jan-08 20:50 
GeneralRe: How to prevent the list box of the combo box appear when catching the CBN_DROPDOWN message? Pin
Hamid_RT27-Jan-08 21:10
Hamid_RT27-Jan-08 21:10 
GeneralVideo Files to VCD\DVD Conversion Pin
Akin Ocal27-Jan-08 11:40
Akin Ocal27-Jan-08 11:40 
GeneralFile IO using Assembly and C Pin
Umer Sheikh27-Jan-08 10:27
Umer Sheikh27-Jan-08 10:27 
GeneralRe: File IO using Assembly and C Pin
Luc Pattyn27-Jan-08 11:51
sitebuilderLuc Pattyn27-Jan-08 11:51 
GeneralRe: File IO using Assembly and C Pin
Umer Sheikh27-Jan-08 12:02
Umer Sheikh27-Jan-08 12:02 
GeneralRe: File IO using Assembly and C Pin
Mark Salsbery27-Jan-08 12:12
Mark Salsbery27-Jan-08 12:12 
GeneralRe: File IO using Assembly and C Pin
Umer Sheikh27-Jan-08 12:20
Umer Sheikh27-Jan-08 12:20 
GeneralRe: File IO using Assembly and C Pin
Umer Sheikh27-Jan-08 12:42
Umer Sheikh27-Jan-08 12:42 
GeneralRe: File IO using Assembly and C Pin
Luc Pattyn27-Jan-08 12:47
sitebuilderLuc Pattyn27-Jan-08 12:47 
GeneralMFC: printing a document through drawing on a CScrollView Pin
Sternocera27-Jan-08 4:41
Sternocera27-Jan-08 4:41 
GeneralRe: MFC: printing a document through drawing on a CScrollView Pin
bob1697227-Jan-08 6:42
bob1697227-Jan-08 6:42 
QuestionHow to Implent Browser/Server Architecture under Linux Pin
cy163@hotmail.com27-Jan-08 4:11
cy163@hotmail.com27-Jan-08 4:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.