I need to create a control structure to run a hangman program

Hi folks,

I'm praying for a speedy response.

Right now I have a hangman program that runs on a while loop, using the conditions: lost, won or still playing.

This is using a manual input of a word.

I need to create a different version of this program where I would ask the player to pick between 1 and 23 (a list of words with hints in between) and then from that choice, a file will be opened and a secret word will be displayed (with ? for every letter) and then a hint.

The file is arranged like this

word01
hint
word02
hint

I have to display the word masked, and then the hint is displayed automatically.

So the ??? words are prime numbers and the hints are even.
There are 46 lines

I need help really badly, it's for my last project to C++, I'd really like to figure it out on my own however I'm running out of time, the semester is almost over.

Any help would be greatly appreciated

Thank you.
ok , so word 1 is at line 1, word 2 at line 3, word 3 at line 5 ....

so if we have an index initialized to 0 :

the word i will be at line : 2*(index = i-1)+1
where index keeps growing by 1 each time

word 1 --> 2*(index=0)+1 = 1.
word 2 --> 2*(index=1)+1 = 3.
word 3 --> 2*(index=2)+1 = 5.

and so on.

so after getting input from the user, calculate the correct line in the file, count the number of chars in that word and display a matching set of "?" (maybe keep the actual word in a variable), and the display the next line in the file -- the hint to the user.

hope this helps, i'll be happy to answer more specific questions about your project.
Last edited on
Is that 2 * as in two times the (index=0) +1 =1?

And input as in cin >> some_number; ?

Right now my other program has a masking tool which is a for loop
Our instructor actually wrote it for us so I'm not entirely sure on the details.

how would this program look like?
What libraries would I need to include?

I'm thinking

using namespace std;
#include fstream (file reading)

void Main (void)

Could the for loop be in the main?

I am trying to make my display follow something like this after I run the program:

Hello and welcome to HANGMAN <---- no problem
Please choose a number between 1 and 23 _

user enters say 6

Gallow screen no mistakes shows up

masked word status ??????

number of incorrect entries:

Please enter a letter_

thank you for the help I appreciate it
yes, 2 times(i - 1) + 1.

examples are :
so word number 13 is at 2* (13-1) + 1 = 25.
and word number 23 is at 2* (22) + 1 = 45.

so, we get input from the user with cin>>number.
youll have to check the input (that a number 1- 23 was given).

if the user chooses number 6 for example, you will have to read the corresponding word from the file, so word 6 is at - 2*(6-1) + 1 = 11.

save the word to a variable, and check its length.
display a matching set of ??????, and the hint (next line from the file) to the user.

then prompt the user for a letter in a loop ( i think it will have to be a while loop, think about the condition..)

in each iteration, the user enters his letter - and you will have to check if that letter is in the actual word. if it is ... if not ...

try translating what you understand into actual code and post your results for further help.
Topic archived. No new replies allowed.