What is wrong with my code?

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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#include <iostream> 
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>


using namespace std;

string make_Stars(int num_Of_Stars);
string get_The_Word();
void humanHead();
void the_Neck();
void the_Frakin_Body();
void left_Arm();
void right_Arm();
void left_Leg();
void right_Leg(int guesses);

int main()
{	
	char user_Letter_Guess;
	string word_To_Guess;
	string GUESSED;
	int number_Of_Stars, wrong_Guess, right_Guess, length_Word, location, bparts;
	
	word_To_Guess = get_The_Word();

	GUESSED = make_Stars(number_Of_Stars);
	length_Word = word_To_Guess.length();
	wrong_Guess = 0;
	right_Guess = 0;

	while((wrong_Guess < 7) && (right_Guess < length_Word))
	{
		cout << "Your word is " << GUESSED << endl;
		cout << "Give me a guess--> ";
		cin >> user_Letter_Guess;
		location = word_To_Guess.find(user_Letter_Guess);

		if(word_To_Guess.find(user_Letter_Guess) == string::npos)
		{
			cout << "Wrong!" << endl;
			wrong_Guess++;
		}
		else
		{
			cout << "Correct!" << endl;
			right_Guess++;
			user_Letter_Guess[location] = '*';
			GUESSED[location] = user_Letter_Guess;
		}
		
		if(wrong_Guess == 1)
			humanHead();
		if(wrong_Guess == 2)
			the_Neck();
		if(wrong_Guess == 3)
			left_Arm();
		if(wrong_Guess == 4)
			the_Frakin_Body();
		if(wrong_Guess == 5)
			left_Leg();
		right_Leg(wrong_Guess);

	}

	return 0;
}

string make_Stars(int number_Of_Stars)
{
	string can_Do = ""; 
	int adding;
	string word;

	word = get_The_Word();
	number_Of_Stars = word.length();
	adding = 0;

	while(adding < number_Of_Stars)
	{
		can_Do = can_Do + "*";
		++adding;
	}
	return can_Do;
}
string get_The_Word()
{
	ifstream bring_In;
	int num_Of_Words;
	int guess_Word;
	string the_Word_To_Guess;
	string word1, word2, word3, word4;

	srand(time(NULL));

	bring_In.open("words.dat");
	bring_In >> num_Of_Words;
	getline(bring_In, word1);
	getline(bring_In, word2);
	getline(bring_In, word3);
	getline(bring_In, word4);

	guess_Word = rand() % num_Of_Words + 1;

	if(guess_Word == 1)
	{
		the_Word_To_Guess = word1;
	}
	if(guess_Word == 2)
	{
		the_Word_To_Guess = word2;
	}
	if(guess_Word == 3)
	{
		the_Word_To_Guess = word3;
	}
	if(guess_Word == 4)
	{
		the_Word_To_Guess = word4;
	}

	bring_In.close();

	return the_Word_To_Guess;
}
void humanHead()
{

	cout << "---------" << endl;
	cout << "| ^   ^ |" << endl;
	cout << "|   <   |" << endl;
	cout << "|  ***  |" << endl;
	cout << "---------" << endl;
}
void the_Neck()
{
	cout << "---------" << endl;
	cout << "| ^   ^ |" << endl;
	cout << "|   <   |" << endl;
	cout << "|  ***  |" << endl;
	cout << "---------" << endl;
	cout << "   |||   " << endl;
	cout << "   |||   " << endl;
}
void left_Arm()
{
	cout << "---------" << endl;
	cout << "| ^   ^ |" << endl;
	cout << "|   <   |" << endl;
	cout << "|  ***  |" << endl;
	cout << "---------" << endl;
	cout << "   |||   " << endl;
	cout << "   |||   " << endl;
	cout << "  /      " << endl;
	cout << " /       " << endl;
	cout << "/        " << endl;
}
void the_Frakin_Body()
{
	cout << "---------" << endl;
	cout << "| ^   ^ |" << endl;
	cout << "|   <   |" << endl;
	cout << "|  ***  |" << endl;
	cout << "---------" << endl;
	cout << "   |||   " << endl;
	cout << "   |||   " << endl;
	cout << "  /|-|   " << endl;
	cout << " / |*|   " << endl;
	cout << "/  |*|   " << endl;
	cout << "   ---   " << endl;
}
void right_Arm()
{
	cout << "---------" << endl;
	cout << "| ^   ^ |" << endl;
	cout << "|   <   |" << endl;
	cout << "|  ***  | /" << endl;
	cout << "---------/" << endl;
	cout << "   |||  /  " << endl;
	cout << "   ||| /   " << endl;
	cout << "  /|-|   " << endl;
	cout << " / |-|   " << endl;
	cout << "/  |-|   " << endl;
	cout << "   ---   " << endl;
}
void left_Leg()
{
	cout << "---------" << endl;
	cout << "| ^   ^ |" << endl;
	cout << "|   <   |" << endl;
	cout << "|  ***  | /" << endl;
	cout << "---------/" << endl;
	cout << "   |||  /  " << endl;
	cout << "   ||| /   " << endl;
	cout << "  /|-|   " << endl;
	cout << " / |-|   " << endl;
	cout << "/  |-|   " << endl;
	cout << "   ---   " << endl;
	cout << "  ||     " << endl;
	cout << "  ||     " << endl;
	cout << "  ||     " << endl;
	cout << " <__|    " << endl;
}
void right_Leg(int guesses)
{

	if(guesses == 6)
	{
	cout << "---------" << endl;
	cout << "| ^   ^ |" << endl;
	cout << "|   <   |" << endl;
	cout << "|  ***  | /" << endl;
	cout << "---------/" << endl;
	cout << "   |||  /  " << endl;
	cout << "   ||| /   " << endl;
	cout << "  /|-|   " << endl;
	cout << " / |-|   " << endl;
	cout << "/  |-|   " << endl;
	cout << "   ---   " << endl;
	cout << "  || ||    " << endl;
	cout << "  || ||    " << endl;
	cout << "  || ||    " << endl;
	cout << " <__||_>   " << endl;
	cout << "You Lose!  " << endl;
	}
}


It where I have [location] that it is an array item. What am I doing wrong with it?
Line 22 char user_Letter_Guess; is not declared or initialized as an array, however in line 50 user_Letter_Guess[location] = '*';
you are attempting to use user_Letter_Guess as an array.

Return 0;
So what do I do that would get the same point across?
????
Ummm...make it an array.
I'm not allowed. It has to be w/out array
what are you trying to do by setting user input to '*'?
and shouldn't user input just be 1 char?

also i would suggest finding the "location" inside a loop which is inside the else block. For when there are more than one of the same Letter.
For example letter has two 'e' s and 't' s. with the current code that u have now (ignoring the array, still don't get that) when u put in e and t for the word letter you would have *et*** when you should really have *ette*.

and this isn't important and the program would work fine with out it: change the while loop inside num_of_chars() to a for loop

any way i might be completely wrong im just a high school kid + newb

return 1;//until i know what right guesses is for
I think you meant to make user_Letter_Guess an std::string.

I think you meant to make user_Letter_Guess an std::string.
|


clarify for me?
1
2
3
4
//char user_Letter_Guess;
std::string user_Letter_Guess;
string word_To_Guess;
string GUESSED;
now it tells me that it cannot convert from std::string to a char. What do I do? typecast/
the only problem now is turning the * into the char value the user puts in if correct. how do i do that?
Topic archived. No new replies allowed.