Checking for a Char in Char Array;

My brain has shut off, I know how to do this, i just cant seem to put it together.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
char seat;
letter = 'A';
char alphabet[26];
int seats_amt = 5; //this is actually a user defined var.
 
cin >> seat;
		
		if (islower(seat))
			seat = toupper(seat);
		

		for (int i = 0; i < seats_amt; i++) {
			alphabet[i] = i + letter;
		if (seat == alphabet[i]) 
			cout << "You entered " << alphabet[i] << endl;
		else
		{
			cout << "Re-enter Letter.\n>";
			cin >> seat;
		}
		}


the problem is that i need to check the input 'seat' against each iteration of the alphabet in the array. but alphabet[i] only works in the for loop bracket. But keeping it in the for loop spits out the ELSE bracket 5 (seats_amt) times.

i feel like its such a stupid and obvious thing that im missing here.
There are many ways to solve this. Functions would be the best. Do you know how to use functions?
Topic archived. No new replies allowed.