assistance required, hangman game.

Posted by Phillip Gibson on Stack Overflow See other posts from Stack Overflow or by Phillip Gibson
Published on 2012-09-30T04:23:58Z Indexed on 2012/09/30 9:37 UTC
Read the original article Hit count: 259

Filed under:
|
|

I am making a hangman game and am having trouble with part of it.

I have selected a random word from a file, but I want to display the word as a series of undersocres __ and then match the letter chosen to a position in the undersocres.

Can anyone help me?

      cout <<"1. Select to play the game\n";
cout <<"2. Ask for help\n";
cout <<"3. Select to quit the game\n";

cout << "Enter a selection: ";
int number;
cin >> number;

    while(number < 1 || number > 3 || cin.fail())
    {
        if(cin.fail())
        {
            cin.sync();   
            cin.clear();   
            cout << "You have not entered a number, please enter a menu selection between 1 and 3\n";
            cin >> number;
        }
        else 
        {
            cout << "Your selection must be between 1 and 3!\n";
            cin >> number;
        }
    }

switch (number)
{
    case 1: 
        {
         string word;
         string name;
        cout << " Whats your name? ";
        cin >> name;

        Player player();

          ifstream FileReader;
          FileReader.open("words.txt");

          if(!FileReader.is_open())
            cout << "Error";

          //this is for the random selection of words

          srand(time(0));
          int randnum = rand()%10+1;             

          for(int counter = 0; counter < randnum; counter++)
            {
                getline(FileReader, word, '\n');
            }

                cout << "my word: " << word << "\n"; 

                // get length of word
                int length;


                //create for loop
                for(int i = 0; i < length; i++)
                    cout << "_";

                //_ _ _ _ _


                SetCursorPos(2,10);

                FileReader.close();
                break;

© Stack Overflow or respective owner

Related posts about c++

Related posts about displaying