Im stuck on this problem for an assignment and am looking for a push in the right direction.

Write a value-returning function, isVowel, that returns the value true if a given character is a vowel and otherwise return flase.

one way i can think of, and this may be thinking too hard, is to make two arrays. One char and one int. both of size 26.

The int array contains the numbers 1-26 and the char array contains the characters a-z.

then have a loop that goes through the char array looking at each character one by one until it finds the same one entered into it. it saves the location of that character as an int variable, then it checks the same spot in the int array.

If the number in the int array, that mirrors the character in the same position in the char array, is the same as the position of a vowel in the alphabet, it should return true. otherwise it should return false. so if the int in the array is equal to any of the following numbers, it should return true:

1 = a
5 = e
9 = i
15 = o
21 = u
and if you consider y a vowel
25 = y

Does that make sense?

You know how to pass the value to be tested to you function, right? And how to return true or false?

So your middle part is how to determine if the tested value is a vowel. The vowels are a,e,i,o,u (and sometimes y). Compare to those characters (probably both the upper and lower case versions), and the first time you come to a match, return true. If you do all the comparisons without finding a match, return false.

Actually, you'd only need the char array, which would look like this:

char alphabet[26] = {'a','b','c','d','e','f','g','h','i',''j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}

so in this case, search the array for a char that matches the char entered into the function. if the position of that equals the position in the alphabet of any vowel - 1, return true. So:

a = 0
e = 4
i = 8
o = 14
u = 20
y = 24

If you need to handle both upper case and lower case, you can either run the tolower command to make it lower case before searching the array, or double the size of the array and add the upper case alphabet and figure out the position of each upper case vowel.

I hope you understand that a little better.

You know how to pass the value to be tested to you function, right? And how to return true or false?

So your middle part is how to determine if the tested value is a vowel. The vowels are a,e,i,o,u (and sometimes y). Compare to those characters (probably both the upper and lower case versions), and the first time you come to a match, return true. If you do all the comparisons without finding a match, return false.

Ahh...See, I knew I was thinking too hard. His way is much simpler. haha. Oh Well. Either way posted so far should work fine. But vmanes is much simpler to run.

How about a shorter version:

char vowels[10] = {'a','e','i','o','u','A','E','I','O','U' };

If the value is found in the array at all, it's a vowel, otherwise, not.

How about a shorter version:

char vowels[10] = {'a','e','i','o','u','A','E','I','O','U' };

If the value is found in the array at all, it's a vowel, otherwise, not.

So should I just use bool to determine if the cin is in the array?

edit: and if so how do I go about doing that? Is there a special syntax?

You'll have to compare your target char to each element of the array. If there's a match, return true, if you get all the way through without a match, return false.

This article has been dead for over six months. Start a new discussion instead.