Vowel

I am new to c++ and have an assignment to create a function called isVowel that checks if a character entered is a vowel or not and return it back to main to output. Any help would be much appreciated i am stuck.

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
#include <iostream>

using namespace std;

bool isVowel(char);

int main(){

	char ch;
	
	cout << "enter" << endl;
	cin >> ch;

	bool isvowel = isVowel(ch);

	if (isvowel == true)
		cout << "It is a vowel" << endl;

	

	return 0;
	
	}//  Function Main()
// =====================

bool isVowel(char ch) {
			if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
				return true;
			else 
				return false;
What's the problem?

At first glance, your code looks like it should work. If you're seeing a problem, then tell us what it is - we're not telepaths!
You're missing a closing brace on your isVowel function, but I assume this is just a copy-paste error.

Some extraneous suggestions:
You may want to add an else-branch after line 16 & 17 to let the user know when a letter isn't a vowel.

Note that if (isvowel == true) is equivalent to if (isvowel) because isvowel is already a bool.

Your is Vowel function can similarly be reduce to
return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
or, equivalently,
return std::string("aeiou").find(ch) != std::string::npos;
Last edited on
Topic archived. No new replies allowed.