forked from mishrahrishikesh/CPPExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVowelChecker.cpp
More file actions
42 lines (30 loc) · 909 Bytes
/
VowelChecker.cpp
File metadata and controls
42 lines (30 loc) · 909 Bytes
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
/*
Is Character a Vowel Program #18
Write a value-returning function, isVowel, that returns the value true if a
given character is a vowel and otherwise returns false.
You may name the program as you please, for example, "VowelChecker.cpp"
Please make sure the program compiles and runs as it should!
*/
#include <iostream>
using namespace std;
bool isVowel(char c);
int main(){
char ch, up;
bool vowel;
cout << "Please enter a character: ";
cin >> ch;
//checks if character is alphabetic, then converts it to uppercase and calls isVowel function
if(isalpha(ch)){
up = toupper(ch);
vowel = isVowel(up);
}
cout << (vowel? "true": "false");
return 0;
}
//takes user-input character and checks if it is in list of vowels
bool isVowel(char c){
if(c=='A'||c=='E'||c=='I'||c=='O'||c=='U'){
return true;
}
return false;
}