Find the mistake.

Ok, i've wrote the code. But i can't find the mistake i've done. Can somebody please help me...
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
#include<iostream>
#include<iomanip>
using namespace std;
void scedulejeff (char [][4]);
void sceduleanna (char [][4]);
void Print2DArray(char [][4]);

int main()
{
	char jeffarray [4][4];
	char annaarray [4][4];
	char instructor;
	
	cout << "What instructor would you like to scedule a time slot for, for Jeff enter j, for Anna enter a?\n";
	cin >> instructor;
	
	if ((instructor == 'j') || (instructor == 'J'))
	{
		scedulejeff (jeffarray);
	}
	
	if else ((instructor == 'a') || (instructor == 'A'))
	{
		scedulejeff (annaarray);
	}
	
	else 
	{
		cout << "you entered an invalid charater please enter a 'j' for Jeff or 'a' for Anna.\n";
	}
	
}

You don't have function definitions in place.

What's the problem you're experiencing with the code?
it it because "if else" should be "else if" ???
Yep. That, and...

Try char instructor[2];
Reason why: All strings have a terminating null character at the end. So the actual length of a string is (what you see)++

And are you sure you want to use bitwise operators for those? Just a note. It doesn't affect how the code runs too much in this particular case.

-Albatross

P.S.- Type checking.
Last edited on
ok, i have a bigger problem. when i run the program (something like this);

"Which swimming instructor would you like to choose? Enter j for Jeff, Enter a for Anna
j

Please enter the first letter of the day of the week you would like to schedule.
M for Monday, T for Tuesday, W for Wednesday, R for Thursday.
m

Please enter a time, 11, 12, 1, or 2.
0You entered an invalid time."

the problem is, i only put j, and m myself. i didn't put 0 myself. what's the problem?

here's the entire 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#include<iostream>
#include<iomanip>
using namespace std;
void scedulejeff (char [][4]);
void sceduleanna (char [][4]);
void Print2DArray(char [][4]);
int X;

int main()
{
	char jeffarray [4][4];
	char annaarray [4][4];
	char instructor;
	
	cout << "Which swimming instructor would you like to choose? Enter j for Jeff, Enter a for Anna\n";
	cin >> instructor;
	
	if ((instructor == 'j') || (instructor == 'J'))
	{
		scedulejeff (jeffarray);
	}
	
	else if ((instructor == 'a') || (instructor == 'A'))
	{
		scedulejeff (annaarray);
	}
	
	else 
	{
		cout << "You've entered an invalid alphabet. Please choose between j for Jeff, or a for Anna.\n";
	}
	
}

void scedulejeff (char a1 [][4])
{
	char day;
	int time;
	
	cout << "Please enter the first letter of the day of the week you would like to schedule.\n" 
			"M for Monday, T for Tuesday, W for Wednesday, R for Thursday.\n";
	cin >> day;
	
	cout << "Please enter a time, 11, 12, 1, or 2.\n"; 
	cout << time;
	
	switch (day)
	{
		case 'M':
		case 'm':
			if (time == 11)
			{
				a1 [0][0] = X;
			}
			
			else if (time == 12)
			{
				a1 [1][0] = X;
			}
			
			else if (time == 1)
			{
				a1 [2][0] = X;
			}
			
			else if (time == 2)
			{
				a1 [3][0] = X;
			}
			
			else
			{
				cout << "You entered an invalid time.\n";
				return;
			}
			break;
			
		case 'T':
		case 't':
			if (time == 11)
			{
				a1 [0][1] = X;
				
			}
			
			else if (time == 12)
			{
				a1 [1][1] = X;
			}
			
			else if (time == 1)
			{
				a1 [2][0] = X;
			}
					   
			else if (time == 2)
			{
				a1 [3][1] = X;
			}
			
			else
			{
				cout << "You've entered an invalid time.\n";
				return;
			}
			break;
			
			case 'W':
			case 'w':
				if (time == 11)
				{
				a1 [0][2] = X;
				}
			
				else if (time == 12)
				{
				a1 [1][2] = X;
				}
			
				else if (time == 1)
				{
				a1 [2][2] = X;
				}
					   
				else if (time == 2)
				{
				a1 [3][2] = X;
				}
			
				else
				{
				cout << "You've entered an invalid time.\n";
				return;
				}
				break;
			
			case 'R':
			case 'r':
				if (time == 11)
					{
					a1 [0][3] = X;
					}
			
					else if (time == 12)
					{
					a1 [1][3] = X;
					}
			
					else if (time == 1)
					{
					a1 [2][3] = X;
					}
					   
					else if (time == 2)
					{
					a1 [3][3] = X;
					}
			
					else
					{
					cout << "You've entered an invalid time.\n";
					return;
					}
					break;
					   
					defaut:
					cout<< "You've entered an invalid day.";
					return;
					}
	}

void sceduleanna (char a1 [][4])
{
	char day;
	int time;
	cout << "Please enter the first letter of the day of the week you would like to schedule.\n" 
			"M for Monday, T for Tuesday, W for Wednesday, R for Thursday.\n";
	cin >> day;
	
	cout << "Please enter a time, 11, 12, 1, or 2.\n"; 
	cin >> time;
	
		switch (day)
		{
		case 'M':
		case 'm':
				if (time == 11)
				{
				a1 [0][0] = X;
				}
					   
				else if (time == 12)
				{
				a1 [1][0] = X;
				}
					   
				else if (time == 1)
				{
				a1 [2][0] = X;
				}
					   
				else if (time == 2)
				{
				a1 [3][0] = X;
				}
				
				else
				{
				cout << "You've entered an invalid time.\n";
				return;
				}
				break;
					   
		case 'T':
		case 't':
			if (time == 11)
			{
			a1 [0][1] = X;
			}
					   
			else if (time == 12)
			{
			a1 [1][1] = X;
			}
					   
			else if (time == 1)
			{
			a1 [2][0] = X;
			}
				   
			else if (time == 2)
			{
			a1 [3][1] = X;
			}
				   
			else
			{
			cout << "You've entered an invalid time.\n";
			return;
			}
			break;
				   
		case 'W':
		case 'w':
			if (time == 11)
			{
			a1 [0][2] = X;
			}
							  
			else if (time == 12)
			{
			a1 [1][2] = X;
			}
				   
			else if (time == 1)
			{
			a1 [2][2] = X;
			}
			
			else if (time == 2)
			{
			a1 [3][2] = X;
			}
			
			else
			{
			cout << "You've entered an invalid time.\n";
			return;
			}
			break;
				   
	case 'R':
	case 'r':
		if (time == 11)
		{
		a1 [0][3] = X;
		}
							  
		else if (time == 12)
		{
		a1 [1][3] = X;
		}
				   
		else if (time == 1)
		{
		a1 [2][3] = X;
		}
				
		else if (time == 2)
		{
		a1 [3][3] = X;
		}
							  
		else
		{
		cout << "You've entered an invalid time.\n";
		return;
		}
		break;
							  
		defaut:
		cout<< "You've entered an invalid day.";
		return;
		}
	}

							  
void Print2DArray(char arr1[][4])
{
	int i = 0, j;
	while (i < 3)
	{
	  j = 0;
	
	while (j < 3)
	{
	cout<<setw(5)<<arr1[i][j];
	j++;
	}
				   
	cout<<endl;
	i++;
	}
}
Last edited on
WHOO! That was a lot of reading.

@Line 45:
Did you mean cin >> time; ?

-Phoenix

P.S.- I stand corrected about the detail about the terminating null character. I guess cin deals with that (I'm an stdio kind of guy).
Last edited on
you are a saviour!!! thanks!!!
You're absolutely welcome. I'll be enabling PMs on my account, so feel free to contact me should you have any further questions.

-Albatross
Should line 25 be:

sceduleanna (annaarray);?

Topic archived. No new replies allowed.