From afc3a2b255937caac43bc652231facf626e8fb6f Mon Sep 17 00:00:00 2001 From: mpelu <35860173+mpelu@users.noreply.github.com> Date: Sun, 13 Oct 2019 17:20:08 -0400 Subject: [PATCH] Create VowelChecker.cpp --- VowelChecker.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 VowelChecker.cpp diff --git a/VowelChecker.cpp b/VowelChecker.cpp new file mode 100644 index 0000000..676f757 --- /dev/null +++ b/VowelChecker.cpp @@ -0,0 +1,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 +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; +}