Storing Char Problems

Hi everyone. I got a few projects from school today. The last one I need to do is make a program were the user enters a vowel from the keyboard. If it is a vowel display "Ok, if not... dispaly "Please enter a vowel. I have the basis of the program down and it compiles and works fine. I am having problems figuring out how to store the Vowels though. At first I though an Enum would work being

enum Vowel { A, a E, e, I, i, O, o ,U ,u

but I get one of two errors being that "A is undefined and the other being that there are two many enum points.

I changed the enum to just declaring chars but that dosen't work either nor does an array.

Does anyone have any idea as to how I can store the vowels so I can refrence them in the "for" statements?

Here is what I have 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
#include <string>
#include <iostream>
	using namespace std;

	
int vowel;
char vowels = A, a, E, e, I, i, O, o, U, u;

int main()
{
	
	cout << "Please enter a vowel: " << endl;
	cin >> vowel;

	if(vowel ==	vowels)
	{
		cout << "Ok" << endl;
	}
	
    if(vowel != vowels)
	{
		cout << "Please enter a vowel" << endl;
	}

	return 0;
}

I'm not sure how you were using your enums, but you have a typo. E and a share a spot.
http://cplusplus.com/doc/tutorial/other_data_types/
^Tutorial.

Aside from that, at line 7, you should probably create and use an array. What you have there won't work. Below is a tutorial on arrays that should teach you everything you need to know to use your array.
http://cplusplus.com/doc/tutorial/arrays/

Enjoy!

-Albatross

...oh, and why is vowel an int? Make it a char.
I would use a char array and when you are declaring them remember to use 'a', 'b', etc...
This could be a way to do it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;

int main()
{
	char vowel_input;
		
	cout << "Please enter a vowel: ";
	cin >> vowel_input;

	while (vowel_input != 'a' && vowel_input != 'e' && vowel_input != 'i' && vowel_input != 'o' && vowel_input != 'u' 
&& vowel_input != 'A' && vowel_input != 'E' && vowel_input != 'I' && vowel_input != 'O' && vowel_input != 'U')
	{
		cout << "Error, please enter vowel again: ";
		cin >> vowel_input;
	}

	cout << "Ok \n";
	
	return 0;
}
I wouldn't check for lower AND uppercase characters - just convert it using some simple ASCII knowledge. A do-while loop seems more elegant in this particular case, too.
Topic archived. No new replies allowed.