Please help with game

Game crashes at line 95 any ideas on why?

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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155

#void guessword(string word)
	 {
	 // Initialize variables
	 char letter;
	 int position;

	 //Creaye string for word
	 string blankword[4];

	 //Fill the array
	 blankword[0] = "_";
	 blankword[1] = "_ ";
	 blankword[2] = "_ ";
	 blankword[3] = "_ ";


	 //Used as ounter
 int x = 1;

	for (int i=1;i<8;i++)
	{
	 cout << "What letter would you like to guess?";
	 cin >>letter;

	position = word.find(letter);

	if (position > word.length()){

	 cout<<letter<< " is not in the word "<<endl;
	 

	 drawing(x++);
	}
  if(x==8){
	  string l;
	  cout << "GAME OVER!" << endl;

	cin.ignore(); 
	getline(cin, l);
		exit(EXIT_FAILURE);
  }
 
	else
	{
	cout<< letter << " is in the word"<<endl;

	if(position==0)
	{
	 blankword[0] = letter;

	 cout << blankword[0]<<blankword[1]<<blankword[2]<<blankword[3];

	 i--;
	 }
	 else if(position==1)
	 {

	 blankword[1] = letter;

	 cout<<blankword[0]<<blankword[1]<<blankword[2]<<blankword[3];

	 i--;
	 }
	 else if(position==2)
	 {

	 blankword[2] = letter;
	 cout<<blankword[0]<<blankword[1]<<blankword[2]<<blankword[3];
	 i--;
	 }

	 else if (position==3)
	 {
	 blankword[3] = letter;
	 cout<<blankword[0]<<blankword[1]<<blankword[2]<<blankword[3];
	 i--;
	 }

	 }

	 }     



	 }

 



	 void drawing(int position)
	 {
	
	 switch(position)
	 {
	 case 1:
	 cout << " ___________"<<endl;
	 cout << " | }"<<endl;
	 cout << " | " <<endl;
	 cout << "_|______________"<<endl;
	 ++position;
	 break;

	 case 2:
	 cout << " ___________"<<endl;
	 cout << " | }"<<endl;
	 cout << " | \\ " <<endl;
	 cout << "_|______________"<<endl;
	 break;

	 case 3: cout << " ___________"<<endl;
	 cout << " | }"<<endl;
	 cout << " | \\ O " <<endl;
	 cout << "_|______________"<<endl;
	 break;

	 case 4:
	 cout << " ___________"<<endl;
	 cout << " | }"<<endl;
	 cout << " | \\ O /" <<endl;
	 cout << "_|______________"<<endl;
	 break;

	 case 5:
	 cout << " ___________"<<endl;
	 cout << " | }"<<endl;
	 cout << " | \\ O /" <<endl;
	 cout << " |  | "<<endl;
	 cout << "_|______________"<<endl;
	 break;

	 case 6:
	 cout << " ___________"<<endl;
	 cout << " | }"<<endl;
	 cout << " | \\ O /" <<endl;
	 cout << " |  |"<<endl;
	 cout << " |  / "<<endl;
	 cout << "_|______________"<<endl;
	 break;

	 case 7:
	 cout << " ___________"<<endl;
	 cout << " | }"<<endl;
	 cout << " | \\ 0 /" <<endl;
	 cout << " |  |"<<endl;
	 cout << " |  / \\ "<<endl;
	 cout << "_|______________"<<endl;
	 }
	 }      

 


The problem is that you aren't passing the same value "position" from your first function to the next.

Your drawing(int position) function accesses nothing because you did not initialize it before you put it into your switch statement.

Two solutions:

1. Make a class with a "position" variable that can be accessed by both your drawing and guessword functions.

2. Make void drawing into int drawing, allowing you to call that function for your desired variable and output "position"

Hope that helps.
Also why do you have the pound sign (#) before the function?
AFAIK it is only used for preprocessor's.
http://www.cplusplus.com/doc/tutorial/preprocessor/

Also your formatting is hard for me to read.

indentcode.net

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
136
137
138
139
140
141
void guessword(string word)
{
    // Initialize variables
    char letter;
    int position;
 
    //Creaye string for word
    string blankword[4];
 
    //Fill the array
    blankword[0] = "_";
    blankword[1] = "_ ";
    blankword[2] = "_ ";
    blankword[3] = "_ ";
 
 
    //Used as ounter
    int x = 1;
 
    for (int i = 1; i < 8; i++) {
	cout << "What letter would you like to guess?";
	cin >> letter;
 
	position = word.find(letter);
 
	if (position > word.length()) {
 
	    cout << letter << " is not in the word " << endl;
 
 
	    drawing(x++);
	}
	if (x == 8) {
	    string l;
	    cout << "GAME OVER!" << endl;
 
	    cin.ignore();
	    getline(cin, l);
	    exit(EXIT_FAILURE);
	}
 
	else {
	    cout << letter << " is in the word" << endl;
 
	    if (position == 0) {
		blankword[0] = letter;
 
		cout << blankword[0] << blankword[1] << blankword[2] << blankword[3];
 
		i--;
	    } else if (position == 1) {
 
		blankword[1] = letter;
 
		cout << blankword[0] << blankword[1] << blankword[2] << blankword[3];
 
		i--;
	    } else if (position == 2) {
 
		blankword[2] = letter;
		cout << blankword[0] << blankword[1] << blankword[2] << blankword[3];
		i--;
	    }
 
	    else if (position == 3) {
		blankword[3] = letter;
		cout << blankword[0] << blankword[1] << blankword[2] << blankword[3];
		i--;
	    }
 
	}
 
    }
 
 
 
}
 
 
 
 
 
void drawing(int position)
{
 
    switch (position) {
    case 1:
	cout << " ___________" << endl;
	cout << " | }" << endl;
	cout << " | " << endl;
	cout << "_|______________" << endl;
	++position;
	break;
 
    case 2:
	cout << " ___________" << endl;
	cout << " | }" << endl;
	cout << " | \ " << endl;
	cout << "_|______________" << endl;
	break;
 
    case 3:
	cout << " ___________" << endl;
	cout << " | }" << endl;
	cout << " | \ O " << endl;
	cout << "_|______________" << endl;
	break;
 
    case 4:
	cout << " ___________" << endl;
	cout << " | }" << endl;
	cout << " | \ O /" << endl;
	cout << "_|______________" << endl;
	break;
 
    case 5:
	cout << " ___________" << endl;
	cout << " | }" << endl;
	cout << " | \ O /" << endl;
	cout << " |  | " << endl;
	cout << "_|______________" << endl;
	break;
 
    case 6:
	cout << " ___________" << endl;
	cout << " | }" << endl;
	cout << " | \ O /" << endl;
	cout << " |  |" << endl;
	cout << " |  / " << endl;
	cout << "_|______________" << endl;
	break;
 
    case 7:
	cout << " ___________" << endl;
	cout << " | }" << endl;
	cout << " | \ 0 /" << endl;
	cout << " |  |" << endl;
	cout << " |  / \ " << endl;
	cout << "_|______________" << endl;
    }
}




Last edited on
# = hash sign
£ = pound sign.

Please try not to mix up my country's currency with random symbols. =/
AFAIK it is hash tag , hash , pound sign , pound , number sign, or number. The real name for it though is octothorpe. Maybe in UK they removed pound/pound sign from the name but in America it is still referred to that unless we are talking about tweets then yeah it is referred to as hash tag. Just like when we go to someones apartment complex the code is referred to as pound x x x or when we talk about a pencil the most common here is "number 2 pencil" (#2).

http://en.wiktionary.org/wiki/octothorpe
http://en.wiktionary.org/wiki/Unsupported_titles/Number_sign
http://en.wiktionary.org/wiki/pound_sign
That is also pretty off topic.
Last edited on
Topic archived. No new replies allowed.