I need help with hangman

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
   string words[]={cat, dog, mom, dad, grandma, grandpa, everything, elephant} ;
   srand((unsigned)time(0)) ;
   int pickword=rand()%8+1 ;
   switch (pickword)
   {
      case 1:

What now?
Firstly, strings need quotes around them ( "cat","dog"... )

Have a string called guess. Make it as long as words[pickword], and fill it with ' ' or '-' or etc. Now what you need to do is ask the user for a char and see if that char is in words[pickword]. If it is there, Write it at the same position in guess. Example: if words[pickword] was "dog" and user entered 'o', guess is now "-o-".
If the char is not found, have an integer lives and subtract one from it.
Repeat this is a loop. If words[pickword] == guess, you win, if lives == 0, you loose.
Topic archived. No new replies allowed.