hangman c++ confusion

i have this hangman project due but i was sick for a week and missed class and i have finals for 3 other classes so im so lost and my teacher dones give a damn so i can here for help. If anyone can help me i would be greatly appreciate it.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
1. Do a nice introduction screen for your hangman program (do this step last).

2. Select a random word and store it in a string variable name SecretWord.

3. Create GuessWord which will be the same size as SecretWord, but all periods (e.g. ". . . . . . . .") 


string GuessWord = SecretWord;
 for (int x = 0; x < SecretWord.size(); x++)
    GuessWord[x] = '.';  

4. Declare an integer named BadGuesses = 0
     Declare a string named Letter
     Declare an integer named Location

5. Set up a while loop for steps 6 - 10.  It should loop as long as BadGuesses < 6 and GuessWord != SecretWord.
 This is the main loop of the program.  The game keeps playing as long as you haven't lost (when BadGuesses = 6) and you haven't won (when GuessWord = SecretWord).

{      // This is the opening brace for the main while loop in the program

     6. Display Graphics (do this step last)

     7. Display Letters Already Guessed (do this step last)

     8. Cout the GuessWord (the placeholder will all periods)

     9. Prompt player to enter a letter (their guess).  Store it in Letter.

     10. If Letter is not located in SecretWord (note: use Letter.find( ), increment BadGuesses

         Else continue looping and find all occurences of Letter in GuessWord and replace the periods. 


  // Step 10
   Location = SecretWord.find(Letter,0);
     if (Location > SecretWord.size())
       BadGuesses++;
     else
       while (Location < SecretWord.size())
     {
       GuessWord.replace(Location,1,Letter);
       Location = SecretWord.find(Letter, Location + 1);
       } 

}

11. If you exit the loop, then you've either won or lost.  Therefore, if BadGuesses == 6, then display "you lose", otherwise display "you win".

Tips - If you do not follow these tips and ask for my help, I will simply tell you to follow these tips.

(a) Comment each step in your code  (e.g.  // Step 3)
 (b) Do the graphics (step 1 & 6) last.  Do step 7 last.
 (c) Do each step and then test it - don't try to do the whole program at once
 (d) Indent your code properly



this is what i got so far

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <iostream>
#include <time.h>
using namespace std;

int main()
{
        srand(time(NULL));
        //step 2
        string words[6]
={"","tomato","guava","grape","pear","apple"};

        string Secretword = words[rand()%6];
        //step 3
        string Guessword = Secretword;
        for (int x = 0; x < Secretword.size(); x++)
        Guessword[x] = '.';



while(totalcount<6 && state<6)
        {
                cout<<"Guess next letter in the following word:";
                for(int k=0;k<a[i].size();k++)
                        cout<<"_ ";

                cout<<"\n\nYour guessing letter:";
                cin>>inword;
                                 for(int j=1;j<=6;j++)
                                    {
                                         b[j] = a[i].substr(j-1, 1);
                                 if(inword==b[j])
                                            wordcount++;
                                     }
                  if(wordcount==0)
                  {  state++;
                  cout<<"Sorry but that was a great try";}
                  else
                    {totalcount++;
                  cout<<"Great guess\n\n";}
                  if(position==0)
                        cout<<inword<<" _ _ _ _ _ _" <<endl;
                else if(position==1)
                        cout<<"_ "<<inword<<" _ _"<<endl;
                else if(position==2)
                        cout<<"_ _ "<<inword<<" _"<<endl;
                else if (position==3)
                        cout<<"_ _ _ "<<inword<<endl;
                else if (position==4)
                        cout<<"_ _ _ _ "<<inword<<endl;
                else if (position==5)
                        cout<<"_ _ _ _ _"<<inword<<endl;
                else if (position==6)
                        cout<<"_ _ _ _ _ _"<<inword<<endl;

                  wordcount=0;
                  Sleep(1500);
              drawgallows(state);
        }
        cout<<a[i]<<endl;

        if(totalcount==6)
          cout<<"\nYou have successfully guessed the word\n\n";

        return 0;
}
        void drawgallows(int state)
{
        if(state==6)
 {

        cout<<endl<<endl
        <<"   +----+     "<<endl
        <<"   |    |     "<<endl
        <<"   |    O     "<<endl
        <<"   |   /|\\   "<<endl
        <<"   |   / \\   "<<endl
        <<"   |Your Dead "<<endl
        <<"  ============"<<endl<<endl;
 }
        else if(state==5)
 {
        cout<<endl<<endl
        <<"   +----+  "<<endl
        <<"   |    |  "<<endl
        <<"   |    O  "<<endl
        <<"   |   /|\\ "<<endl
        <<"   |     \\ "<<endl
        <<"   |       "<<endl
        <<"  ============"<<endl<<endl;
 }
        else if(state==4)
 {
        cout<<endl<<endl
        <<"   +----+  "<<endl
        <<"   |    |  "<<endl
        <<"   |    O  "<<endl
        <<"   |   /|\\ "<<endl
        <<"   |       "<<endl
        <<"   |       "<<endl
        <<"  ============="<<endl<<endl;
 }
        else if(state==3)
 {
        cout<<endl<<endl
        <<"   +----+  "<<endl
        <<"   |    |  "<<endl
        <<"   |    O  "<<endl
        <<"   |   /|  "<<endl
        <<"   |       "<<endl
        <<"   |       "<<endl
   <<"  ============="<<endl<<endl;
 }
        else if(state==2)
 {
        cout<<endl<<endl
        <<"   +----+  "<<endl
        <<"   |    |  "<<endl
        <<"   |    O  "<<endl
        <<"   |    |  "<<endl
        <<"   |       "<<endl
        <<"   |       "<<endl
        <<"  ============="<<endl<<endl;
 }
        else if(state==1)
 {
        cout<<endl<<endl
        <<"   +----+  "<<endl
        <<"   |    |  "<<endl
        <<"   |       "<<endl
        <<"   |       "<<endl
        <<"   |       "<<endl
        <<"   |       "<<endl
        <<"  ============="<<endl<<endl;
 }
 return;




i am so confused can someone let me know if i am doing this correct
Topic archived. No new replies allowed.