Greeting Guys ..

I'm Asked to make the Hangman Game using C++ ..

Acutally I'm stuck in how to put a dictionary of words ( each 5 letters ) inside an array .. and how to compare the input from the user to the word chosen from the dictionary..

I even having problems in how to take randomly a word from the array and ask the user to input it..

i need a simple program to do this

without using fstream nor vectors...

I hope someone can help me as soon as possible..thank you

Recommended Answers

All 2 Replies

Since you are using C++, you can use an array of C++ string to hold your words.

This may help get you started ...

const int MAX_NUM_WORDS = 1000; // make big enough 

// ...

// int main()

string words[MAX_NUM_WORDS];
istream fin( "nameOfYourFileOfWords.txt" );
int n = 0;
if( fin )
{
   string word;
   while( n < MAX_NUM_WORDS && fin >> word )
   {
      words[n] = word;
      ++n;
   }
   fin.close();
}
// if file opened ok ... now your array is filled ok
// and has n words in it ... where n is an int with 
// a possible value of 0 to MAX_NUM_WORDS

or ... without using a file ...

string word;
int n = 0;
// prompt here for input ...
while( n < MAX_NUM_WORDS && cin >> word )
{
  words[n] = word;
  ++n;
  // prompt here for input ...
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.