// I am new to C++ and can not seem to get the falling man to output to the screen. Any help would be greatly appreciated.

#include <iostream>
    #include <windows.h>
    using namespace std;
     
    void DrawBar(char guess);
	
    int main()
    {
        char solution[8]; //holds solution
        char blank[8]; //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 8 chars or less."<<endl;
        cin.getline(solution, 8);
        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 (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;
    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;
       }
	   
//DrawBar(guess);	//Draw the hanging bar at end of game
	//They lost if they are here so tell them the answer.
	//cout<<"The word was : "<<Words[Word]<<endl<<endl;	



// This will Draw the hanging bar according to the state
void DrawBar(char guess)
{
	
	if(guess==5)
	{
		cout<<endl<<endl
			<<"   +--------+  "<<endl
			<<"   |    0      "<<endl
			<<"   |   /|\\     "<<endl
			<<"   |   / \\    "<<endl
			<<"   |           "<<endl
			<<"   | AAHHH!!!  "<<endl
			<<"  ============"<<endl<<endl;
		
		Sleep(500); // Message Sleep for 1 second
		
        cout<<endl<<endl
			<<"   +--------+  "<<endl
			<<"   |           "<<endl
			<<"   |    0     "<<endl
			<<"   |   /|\\   "<<endl
			<<"   |   / \\    "<<endl
			<<"   | AAHHH!!!  "<<endl
			<<"  ============"<<endl<<endl;

		Sleep(500); // Message Sleep for 1 second
    
		cout<<endl<<endl
			<<"   +--------+  "<<endl
			<<"   |           "<<endl
			<<"   |          "<<endl
			<<"   |   0        "<<endl
			<<"   |  /|\\      "<<endl
			<<"   | AAHHH!!!  "<<endl
			<<"  ============"<<endl<<endl; 

		Sleep(500); // Message Sleep for 1 second

		cout<<endl<<endl
			<<"   +--------+  "<<endl
			<<"   |           "<<endl
			<<"   |          "<<endl
			<<"   |           "<<endl
			<<"   |   0       "<<endl
			<<"   | AAHHH!!!  "<<endl
			<<"  ============"<<endl<<endl; 

		Sleep(500); // Message Sleep for 1 second

		cout<<endl<<endl
			<<"   +--------+  "<<endl
			<<"   |           "<<endl
			<<"   |          "<<endl
			<<"   |           "<<endl
			<<"   |           "<<endl
			<<"   | AAHHH!!!  "<<endl
			<<"  ============"<<endl<<endl; 

	}
	else if(guess==4)
	{
		cout<<endl<<endl
			<<"   +---------+  "<<endl
			<<"   |    \\0     "<<endl
			<<"   |     |\\    "<<endl
			<<"   |    / \\    "<<endl
			<<"   |            "<<endl
			<<"   |            "<<endl
			<<"  ============="<<endl<<endl;
	}
	else if(guess==3)
	{
		cout<<endl<<endl
			<<"   +----------+  "<<endl
			<<"   |    \\0/     "<<endl
			<<"   |     |       "<<endl
			<<"   |    / \\     "<<endl
			<<"   |             "<<endl
			<<"   |             "<<endl
			<<"  ============="<<endl<<endl;
	}
	else if(guess==2)
	{
		cout<<endl<<endl
			<<"   +-----------+  "<<endl
			<<"   |  0_:__:      "<<endl
			<<"   |       \\     "<<endl
			<<"   |              "<<endl
			<<"   |              "<<endl
			<<"   |              "<<endl
			<<"  ============="<<endl<<endl;
	}
	else if(guess==1)
	{
		cout<<endl<<endl
			<<"   +-----------+  "<<endl
			<<"   |  0_:__:     "<<endl
			<<"   |              "<<endl
			<<"   |              "<<endl
			<<"   |              "<<endl
			<<"   |              "<<endl
			<<"  ============="<<endl<<endl;
	}

}

Edited 7 Years Ago by __avd: Add [code] tags. Encase your code in: [code] and [/code] tags.

In different versions I have tried, I have been able to get the man to fall on failed attempts. I re-read my project instructions and found out i needed to have a "fill in the blank" in the program. Since I made the changes, I can not get the man to fall.

You're passing a char into your DrawBar() function which is incorrect. Keep a separate int counter to keep track of your guesses and then give that to Drawbar after a guess. You'll never be entering in the characters '1' '2' '3' '4' '5' as part of your alphabet guesses so there is no sense using what would be nonsense anyway.

Also, next time please think of a meaningful title for your post. Not meaning to single you out, but I wanted to say something. It takes 2 seconds and believe it or not people are much more willing to help when they can see what they are getting into.

Edited 7 Years Ago by jonsca: n/a

Thanks for your help. I am new to this and learning. Shouls I use a for statement?

Nope, just have an int that increments with your while loop. You'll have to decide the best place to call DrawBar as it could be reflecting the status after this present turn or showing the user their status before the next guess.

Thanks for the help. Sorry for the slow response I just got home from work. An int counter like a int++?

Exactly. You just want something that's going to keep track each time through the while loop so you can register what guess your user is on.

Could I add it to the end of guess, like guess++? If I changed guess to a int.

I would do it within the while loop after the for loop. Why would you change guess, you need that to be a char. Declare a new int, increment it (++) at the end of the while loop and then call DrawBar(countervariablehere). That way your user knows their status after they've made their guess.

Thanks, would you put it like guess==word. And the word++?

It has nothing to do with guess. Don't mess up the working part of your program. At the top in main() declare int guesscount; After your for loop for(counter =0.....) we've made one guess, so guesscount++; (make sure it's outside of the for loop). Next, call DrawBar(guesscount); However, you'll need to put a condition for greater than 6 in your drawbar because what if it takes the user 6 guesses or more? As it is the program will bypass all of your else if statements.

Edited 7 Years Ago by jonsca: n/a

Here is what I did. I get an infinite loop with it.

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();

		int word = 0;
		word++;
		       
	   
		DrawBar(word);	//Draw the hanging bar at end of game
		//They lost if they are here so tell them the answer.
		//cout<<"The word was : "<<Words[Word]<<endl<<endl;	

	return 0;
	}



// This will Draw the hanging bar according to the state
void DrawBar(int word)
{
	
	if(word==5)
	{
		cout<<endl<<endl
			<<"   +--------+  "<<endl
			<<"   |    0      "<<endl
			<<"   |   /|\\     "<<endl
			<<"   |   / \\    "<<endl
			<<"   |           "<<endl
			<<"   | AAHHH!!!  "<<endl
			<<"  ============"<<endl<<endl;
		
		Sleep(500); // Message Sleep for 1 second

I would do it within the while loop after the for loop.

You have it after the whole thing is over. That does you no good.

//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
         
	word++;
	DrawBar(word);
        
        if(word >=5) break;
        } //game is over.
         if (word >=5)
             cout <<"Lost"<<endl;
         else 
              cout<<"Winner!";
        cin.get();
        return 0;
       }

declare word at the top of main

Edited 7 Years Ago by jonsca: added win code

Thanks for the help. The program still will not draw the man. Any other suggestions? I am burned out of ideas.

Yes, here is what I have......

#include <iostream>
	#include <windows.h>
    using namespace std;

	   
	void DrawBar(int guess);
	
    int main()
    {
        char solution[6]; //holds solution
        char blank[6]; //holds "_"'s for unsolved letters
        int counter = 0; //general-use counter
        int right = 0; //1 = right guess, 0 = wrong guess.
        char guess;
		int guesscount = 0;
		
		
       
        cout<<"Enter phrase 5 chars or less."<<endl;
        cin.getline(solution, 6);
        int puzzLength = strlen(solution); //finds lengtrh of puzzle, stores INT value to puzzlength
  
         
         
  
       
    //convert puzzle to full uppercase
    for (counter = 0; counter < 6/*puzzLength*/; counter++){
       solution[counter] = toupper(solution[counter]);
    }
    //done converting
      
    
 
    strcpy_s(blank, solution); //copy solution to the 'blank' array
      
    for (counter = 0; counter < 6/*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;
    cin>>guess;
	guess = toupper(guess);

	      
    //cbeck guess!
    for (counter = 0; counter <= 6/*puzzLength*/; counter++) {
        
        if (guess == solution[counter]) {
        blank[counter] = guess; //fill in the puzzle with the letter
         
        }
         
		}//close loop, done checking guess

		guesscount++;
		       
	   	DrawBar(guesscount);	//Draw the hanging bar at end of game
		//They lost if they are here so tell them the answer.
		//cout<<"The word was : "<<Words[Word]<<endl<<endl;	

         
		} //game is over.
         
        cout<<"Winner!";
        cin.get();

		
	return 0;
	}



// This will Draw the hanging bar according to the state
void DrawBar(int guess)
{
	if (guess==6)

	if(guess==5)
	{
		cout<<endl<<endl
			<<"   +--------+  "<<endl
			<<"   |    0      "<<endl
			<<"   |   /|\\     "<<endl
			<<"   |   / \\    "<<endl
			<<"   |           "<<endl
			<<"   | AAHHH!!!  "<<endl
			<<"  ============"<<endl<<endl;
		
		Sleep(500); // Message Sleep for 1 second
		
        cout<<endl<<endl
			<<"   +--------+  "<<endl
			<<"   |           "<<endl
			<<"   |    0     "<<endl
			<<"   |   /|\\   "<<endl
			<<"   |   / \\    "<<endl
			<<"   | AAHHH!!!  "<<endl
			<<"  ============"<<endl<<endl;

		Sleep(500); // Message Sleep for 1 second
    
		cout<<endl<<endl
			<<"   +--------+  "<<endl
			<<"   |           "<<endl
			<<"   |          "<<endl
			<<"   |   0        "<<endl
			<<"   |  /|\\      "<<endl
			<<"   | AAHHH!!!  "<<endl
			<<"  ============"<<endl<<endl; 

		Sleep(500); // Message Sleep for 1 second

		cout<<endl<<endl
			<<"   +--------+  "<<endl
			<<"   |           "<<endl
			<<"   |          "<<endl
			<<"   |           "<<endl
			<<"   |   0       "<<endl
			<<"   | AAHHH!!!  "<<endl
			<<"  ============"<<endl<<endl; 

		Sleep(500); // Message Sleep for 1 second

		cout<<endl<<endl
			<<"   +--------+  "<<endl
			<<"   |           "<<endl
			<<"   |          "<<endl
			<<"   |           "<<endl
			<<"   |           "<<endl
			<<"   | AAHHH!!!  "<<endl
			<<"  ============"<<endl<<endl; 

	}
	else if(guess==4)
	{
		cout<<endl<<endl
			<<"   +---------+  "<<endl
			<<"   |    \\0     "<<endl
			<<"   |     |\\    "<<endl
			<<"   |    / \\    "<<endl
			<<"   |            "<<endl
			<<"   |            "<<endl
			<<"  ============="<<endl<<endl;
	}
	else if(guess==3)
	{
		cout<<endl<<endl
			<<"   +----------+  "<<endl
			<<"   |    \\0/     "<<endl
			<<"   |     |       "<<endl
			<<"   |    / \\     "<<endl
			<<"   |             "<<endl
			<<"   |             "<<endl
			<<"  ============="<<endl<<endl;
	}
	else if(guess==2)
	{
		cout<<endl<<endl
			<<"   +-----------+  "<<endl
			<<"   |  0_:__:      "<<endl
			<<"   |       \\     "<<endl
			<<"   |              "<<endl
			<<"   |              "<<endl
			<<"   |              "<<endl
			<<"  ============="<<endl<<endl;
	}
	else if(guess==1)
	{
		cout<<endl<<endl
			<<"   +-----------+  "<<endl
			<<"   |  0_:__:     "<<endl
			<<"   |              "<<endl
			<<"   |              "<<endl
			<<"   |              "<<endl
			<<"   |              "<<endl
			<<"  ============="<<endl<<endl;
	}

}

I made a couple small changes to make sure that we are only updating hangman for wrong guesses. This works on my machine.
(ignore the strcmp_s change,it's a good idea...I was compiling on another sys initially)

#include <iostream>
    #include <windows.h> //has sleep function
     #include <string>
    using namespace std;
     
    void DrawBar(int guess);
	
    int main()
    {
        char solution[8]; //holds solution
        char blank[8]; //holds "*"'s for unsolved letters
        int counter = 0; //general-use counter
        int right = 0; //1 = right guess, 0 = wrong guess.
        char guess;
        int word=0;
	bool found;
        cout<<"Enter phrase 8 chars or less."<<endl;
        cin.getline(solution, 8);
        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(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 (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;
    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
        found = true; 
        }
	
        } //close loop, done checking guess
         if (!found)
		 word++;
	 found = false;
	
	DrawBar(word);
	if(word >=5) break;
        } //game is over.
         if(word >=5)
		 cout <<"Lost"<<endl;
	 else
		 cout<<"Winner!"<<endl;
        cout<<"Winner!";
        cin.get();
        return 0;
       }
	   
//DrawBar(guess);	//Draw the hanging bar at end of game
	//They lost if they are here so tell them the answer.
	//cout<<"The word was : "<<Words[Word]<<endl<<endl;	



// This will Draw the hanging bar according to the state
void DrawBar(int guess)
{
	
	if(guess==5)
	{
		cout<<endl<<endl
			<<"   +--------+  "<<endl
			<<"   |    0      "<<endl
			<<"   |   /|\\     "<<endl
			<<"   |   / \\    "<<endl
			<<"   |           "<<endl
			<<"   | AAHHH!!!  "<<endl
			<<"  ============"<<endl<<endl;
		
		Sleep(500); // Message Sleep for 1 second
		
        cout<<endl<<endl
			<<"   +--------+  "<<endl
			<<"   |           "<<endl
			<<"   |    0     "<<endl
			<<"   |   /|\\   "<<endl
			<<"   |   / \\    "<<endl
			<<"   | AAHHH!!!  "<<endl
			<<"  ============"<<endl<<endl;

		Sleep(500); // Message Sleep for 1 second
    
		cout<<endl<<endl
			<<"   +--------+  "<<endl
			<<"   |           "<<endl
			<<"   |          "<<endl
			<<"   |   0        "<<endl
			<<"   |  /|\\      "<<endl
			<<"   | AAHHH!!!  "<<endl
			<<"  ============"<<endl<<endl; 

		Sleep(500); // Message Sleep for 1 second

		cout<<endl<<endl
			<<"   +--------+  "<<endl
			<<"   |           "<<endl
			<<"   |          "<<endl
			<<"   |           "<<endl
			<<"   |   0       "<<endl
			<<"   | AAHHH!!!  "<<endl
			<<"  ============"<<endl<<endl; 

		Sleep(500); // Message Sleep for 1 second

		cout<<endl<<endl
			<<"   +--------+  "<<endl
			<<"   |           "<<endl
			<<"   |          "<<endl
			<<"   |           "<<endl
			<<"   |           "<<endl
			<<"   | AAHHH!!!  "<<endl
			<<"  ============"<<endl<<endl; 

	}
	else if(guess==4)
	{
		cout<<endl<<endl
			<<"   +---------+  "<<endl
			<<"   |    \\0     "<<endl
			<<"   |     |\\    "<<endl
			<<"   |    / \\    "<<endl
			<<"   |            "<<endl
			<<"   |            "<<endl
			<<"  ============="<<endl<<endl;
	}
	else if(guess==3)
	{
		cout<<endl<<endl
			<<"   +----------+  "<<endl
			<<"   |    \\0/     "<<endl
			<<"   |     |       "<<endl
			<<"   |    / \\     "<<endl
			<<"   |             "<<endl
			<<"   |             "<<endl
			<<"  ============="<<endl<<endl;
	}
	else if(guess==2)
	{
		cout<<endl<<endl
			<<"   +-----------+  "<<endl
			<<"   |  0_:__:      "<<endl
			<<"   |       \\     "<<endl
			<<"   |              "<<endl
			<<"   |              "<<endl
			<<"   |              "<<endl
			<<"  ============="<<endl<<endl;
	}
	else if(guess==1)
	{
		cout<<endl<<endl
			<<"   +-----------+  "<<endl
			<<"   |  0_:__:     "<<endl
			<<"   |              "<<endl
			<<"   |              "<<endl
			<<"   |              "<<endl
			<<"   |              "<<endl
			<<"  ============="<<endl<<endl;
	}

}

Edited 7 Years Ago by jonsca: n/a

This question has already been answered. Start a new discussion instead.