Hey guys, i need some help with a hangman project for school.

The outline is:

make program that plays the game of hangman, read the word to be guessed into a string variable. ( The programmer must make about 10-20 words to have one randomly picked each time a game is started. the player must guess the letters belonging to the word. the words letters must be * before they are guessed correctly.

when the program is started you pick a difficulty level. easy,medium,hard. easy has 15 lives, medium has 10 lives and hard has only 5. each inccorect guess means you lose a life, if all are lost it says game over and then you terminate. maybe use an array for the list of difficultys?

i have started but need some help on the main parts.
try to help me with basic ways of doing it a we havent gone too far yet

we were told to have a variable named solution to keep track of it at any time during the program. intialize solution to a string of *. each time a letter is in the word is guessed replaces that * with the letter in that place

some snippets of ideas i have:

int lives;


if (diff = easy)
{ lives = 5};

Please help =P

Start at the top.
1) Create something in the program that holds 10-20 words. Add a loop to print the words.
Compile and correct until it has no errors and displays what you've done correctly.

2) Add some code to choose a random word. Output the word. Compile and correct until it works.

3) continue...

my main questions are how to store the words, and how to do the part with the **** and replacing them with a letter if its right and in the right position.?

#include <conio.h>  
#include <iostream> 
char firstword[50]; 
char secondword[50]; 




 
int main() 
{ 


firstword = "water";
secondword = "fire";


cout<<water<<fire;



        getch();
        return 0; 
}

Im trying the first part, just trying to see how to pre assign words for use in the program. so one will be randomly picked before the user even types anything in

but its not really working for me..

and no we have no books and i have been on google for hours but it seems a bit advanced as we use hardly any of what i see

Edited 6 Years Ago by zendet: n/a

Do you know what an array is?

Do you know what a string is?

How about a string array?

I'm asking because without knowing what you know, all our help will be over your head.

We did them in class, i just need help rembering.

string is to hold a word as char only holds 1 char.

array im not too sure on...

for my last project i did this, this might help you know how much I know so far

//Olympic Games program
//Created by Wayne Daly
//2009/2010

//Header files
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<iomanip.h>
#include<windows.h>
int main()

{
//Variables    
float judge1score;
float judge2score;
float judge3score;
float judge4score;
float judge5score;
float min;
float max;
int times;
float avg;
char response;

start:
//set colour to green
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);

//Title page, Graphics

cout<<"\n\n\n";
cout<<"   ++++++   ++    ++  ++   +++  +++   +++++++   ++   ++++++ \n";
cout<<"  ++++++++  ++    ++  ++  ++++++++++  ++   +++  ++  ++++++++\n";
cout<<"  ++    ++  ++    ++  ++  ++++++++++  ++   +++  ++  +++   ++\n";
cout<<"  ++    ++  ++    ++  ++  ++  ++  ++  ++   +++  ++  ++      \n";
cout<<"  ++    ++  ++     ++++   ++  ++  ++  +++++++   ++  ++      \n";
cout<<"  ++    ++  ++      ++    ++  ++  ++  ++        ++  +++   ++\n";
cout<<"  ++++++++  ++++++  ++    ++  ++  ++  ++        ++  ++++++++\n";
cout<<"   ++++++   ++++++  ++    ++  ++  ++  ++        ++   ++++++ \n\n";

cout<<"\t\t       ++++++    +++++      ++  ++     ++++++++   ++++++++\n";
cout<<"\t\t      ++++++++  +++++++    ++++++++   ++++++++   +++++++  \n";
cout<<"\t\t      ++        ++   ++   ++++++++++  ++         ++       \n";
cout<<"\t\t      ++  ++++  ++   ++   ++  ++  ++  +++++++    ++++++++ \n";
cout<<"\t\t      ++   ++   +++++++   ++  ++  ++  +++++++    ++++++++ \n";
cout<<"\t\t      ++   ++   +++++++   ++  ++  ++  ++               ++ \n";
cout<<"\t\t      +++++++   ++   ++   ++  ++  ++  ++++++++    +++++++ \n";
cout<<"\t\t        ++++    ++   ++   ++  ++  ++   ++++++++  +++++++  \n";

cout<<"\n\n\t\t\t    ---> Press any key <--- ";
cout<<"\n\t\t\t\t\t\t\t\t  -Wayne Daly-";
getch();
system("CLS");



//start of main program
cout<<"\n\n\t\t\t\t======================\n                                I                    I\n                                I OLYMPIC GAMES 2012 I\n                                I                    I";
cout<<"\n\t\t\t\t======================";
 
 
 
//Asks how many competitors 
cout<<"\n\nEnter how many competitors? ";
cin>>times;
 
//Error validation 
while (times < 1 || times > 50)
      {
            cout<<"\nInvalid entry!";
            cout<<"\nEnter amount of competitors: ";
            cin>>times;
      }
 
//loop for how many competitors
for(int i = 1; i <= times; i++)

        {
         
         //set colour to green
         SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
         //Judge 1   

         cout<<"\n\n\n\n\t\t\tJudge 1 enter score: ";
         cin>>judge1score;

         while (judge1score < 0.0 || judge1score > 6.0)
         
         
         
               {
               cout<<"\n\t\t\tInvalid score";
               cout<<"\n\t\t\tMust be between 0.0 and 6.0!!";
               cout<<"\n\n\t\t\tJudge 1 enter score: ";
               cin>>judge1score;
      
               }      


    
       //judge 2    
       cout<<"\n\n\n\n\t\t\tJudge 2 enter score: ";
       cin>>judge2score;

       while (judge2score < 0.0 || judge2score >6.0)
       
              {
              cout<<"\n\t\t\tInvalid score";
              cout<<"\n\t\t\tMust be between 0.0 and 6.0!!";
              cout<<"\n\n\t\t\tJudge 2 enter score: ";
              cin>>judge2score;
              }

 
       //judge 3
       cout<<"\n\n\n\n\t\t\tJudge 3 enter score: ";
       cin>>judge3score;
       while (judge3score < 0.0 || judge3score > 6.0)
              
              {
              cout<<"\n\t\t\tInvalid score";
              cout<<"\n\t\t\tMust be between 0.0 and 6.0!!";
              cout<<"\n\n\t\t\tJudge 3 enter score: ";
              cin>>judge3score;
              }

       
       //Judge 4
       cout<<"\n\n\n\n\t\t\tJudge 4 enter score: ";
       cin>>judge4score;
       while (judge4score < 0.0 ||judge4score > 6.0)
       
             {
             cout<<"\n\t\t\tInvalid score";
             cout<<"\n\t\t\tMust be between 0.0 and 6.0!!";
             cout<<"\n\n\t\t\tJudge 4 enter score: ";
             cin>>judge4score;
             }



       //judge 5
       cout<<"\n\n\n\n\t\t\tJudge 5 enter score: ";
       cin>>judge5score;       
       while (judge5score < 0.0 || judge5score > 6.0)
       
            {
            cout<<"\n\t\t\tInvalid score";
            cout<<"\n\t\t\tMust be between 0.0 and 6.0!!";
            cout<<"\n\n\t\t\tJudge 5 enter score: ";
            cin>>judge5score;
            }      





      //start of finding lowest number of the 5 inputs

      min=judge1score;

      if (judge2score<min)
      
               {min=judge2score;}


     if (judge3score<min)
     
               {min=judge3score;}


     if (judge4score<min)
     
              {min=judge4score;}


     if (judge5score<min)
     
             {min=judge5score;}


//start of finding highest number of 5 inputs

     max=judge1score;

     if (judge2score>max)
     
           {max=judge2score;}


     if (judge3score>max)

           {max=judge3score;}


     if (judge4score>max)

           {max=judge4score;}


     if (judge5score>max)

           {max=judge5score;}


      //start of  getting average without knowing what the highest and lowest numbers were.

      avg=(judge1score+judge2score+judge3score+judge4score+judge5score)-(min+max);

      avg=(avg/3);


//Set colour to red
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);

      //score table
      cout<<"\n\n\n\n\n\t\t\t   --SCORE TABLE--   ";
      
//set colour to blue      
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 11);
      
      cout<<"\n\n\t\t\tJudge 1 score is: "<<judge1score;
      cout<<"\n\n\t\t\tJudge 2 score is: "<<judge2score;
      cout<<"\n\n\t\t\tJudge 3 score is: "<<judge3score;
      cout<<"\n\n\t\t\tJudge 4 score is: "<<judge4score;
      cout<<"\n\n\t\t\tJudge 5 score is: "<<judge5score;
      cout<<"\n\n\n\t\tThe Average score for this competitor is "<<avg;}
 
 
      //Start of program exit loop


      //If answer = y, or Y
     exit:
     cout<<"\n\n\n\t\tDo you want to exit program?";
     cin>>response;
     if (response ==  'Y' || response ==  'y' )
     
            {
             
             //Goodbye graphics             
             cout<<"\n\n\t\t\t          +\n";
             cout<<"\t\t\t        +   +\n";
             cout<<"\t\t\t      +       +\n";
             cout<<"\t\t\t    +           +\n";
             cout<<"\t\t\t  +               +\n";
             cout<<"\t\t\t+      GOODBYE      +\n";
             cout<<"\t\t\t  +               +\n";
             cout<<"\t\t\t    +           +\n";
             cout<<"\t\t\t      +       +\n";
             cout<<"\t\t\t        +   +\n";
             cout<<"\t\t\t          +\n";

             getch();
             return 0;   
   
             
            }


      //if answer = N or n
      else if (response ==  'N' || response == 'n' )
      
           {
           system("CLS");   
           goto start;                
           }



      // If anything else is input
      else
           {
    
            cout<<"\n\n\n\t\tInvalid input try again: ";
            goto exit;
   
            }













//End of program

}

Edited 6 Years Ago by zendet: n/a

Then look them up. In your notes or in a tutorial.

Or better yet, find a better school that teaches with a book that you can use as a reference.

Comments
very unhelpful, and not polite to new users

wow, thanks for being so helpful..wont be using this site again

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