Thread: Hangman program Help!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    32

    Hangman program Help!

    I made this hangman program and everything works except I have been trying to put a variable named count which adds one everytime an incorrect letter is guessed and after six incorrect guesses the program quits, but i dont know where to put it so that it will work any help would be appreiciated here is my code:
    Code:
    #include<iostream.h>
    #include<console.h>
    #include<string.h>
    
    int main()
    
    {
    
    int count=0;
    int wrong;
    string secret;
    char answer;
    string answer2;
    string cover;
    
    cout<<"Enter word: "<<endl;  //User enters word to be guessed
    cin>>secret;
    
    cover=secret;
    answer2=secret;
    	
    clrscr();// clears screen	
    
    
    	
    for(int i=0; i<secret.length(); i++)//prints dashs to show length of word
    	{
    	cover[i]='-';
    	cout<<cover[i];
    	}	
    
    cout<<endl;
    
    do{
    
    cout<<"Enter your guess($ to guess the whole word and * to quit): "<<endl;
    cin>>answer;
    
    
    
    if(answer=='$')	// Allows you to guess the whole word
    	{
    	cout<<"Enter your letter guess for the whole word: ";
    	cin>>answer2;
    		
    	
    	if(secret==answer2) // checks if word entered is right
    		{
    		cout<<"You are right!"<<endl;
    		answer='*';
    		
    		}	
    	else		
    		{
    		
    		cout<<"incorret, guess again"<<endl;
    		 
    		}
    	}
    else
    	{
    		
    		
    		
    		for(int j=0; j<secret.length(); j++)  //changes dashs to correct letters guessed
    			{
    			if(secret[j]==answer)
    				{
    				cover[j]=answer;
    				 wrong=true;
    				}
    			
    			cout<<cover[j];
    			
    			}
    			
    				cout<<endl;
    				if(wrong!=true)
    				count++;
    		
    			if(count==1)
    				cout<<"O";
    			else if(count==2)
    				cout<<"  O  "<<endl<<"  |  ";
    			else if(count==3)
    				cout<<"  O  "<<endl<<" /| ";	
    			else if(count==4)	
    				cout<<"  O  "<<endl<<" /|\ ";
    			else if(count==5)
    				cout<<"  O  "<<endl<<" /|\\ "<<endl<<" / ";
    			else if(count==6)
    				{
    				cout<<"  O  "<<endl<<" /|\\ "<<endl<<" / \\ ";		
    				cout<<"You've lost!";
    				answer='*';
    				}
    			cout<<" "<<count;
    		cout<<endl;
    		
    		
    		if(secret==cover)   //When all letters guessed program ends
    			{
    			cout<<"You guessed it!";
    			answer='*';
    			}	
    	
    	}	
    }while(answer!='*');
    
    
    
    return(0);
    
    }
    Last edited by venomgts550; 04-18-2002 at 05:33 PM.
    I am a C++ newb
    using: Visual C++ 6.0
    thanx for any Help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with Hangman program
    By Trank07 in forum C Programming
    Replies: 1
    Last Post: 11-24-2007, 10:00 PM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. Help on hangman program
    By vserenev in forum C++ Programming
    Replies: 1
    Last Post: 01-11-2007, 12:34 PM
  4. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM