Write a value-returning function, isVowel, that returns the value true if a given character is a vowel and otherwise returns false.
For the input E, your output should look like the following:
E is a vowel: 1
When printing the value of a bool, true will be displayed as 1 and false will be displayed as 0.
#include <iostream>
bool isVowel(char c)
{
switch(toupper(c))
{
case 'A': case 'E': case 'I': case 'O': case 'U' : return true;
default: return false;
}
}
int main()
{
std::cout << "Please enter some character: ";
char c;
std::cin >> c;
if(!std::cin)
{
std::cerr << "Bad input\n";
return 1;
}
std::cout << c << " is a vowel: " << (isVowel(c) ? "1" : "0") << "\n";
return 0;
}
Comments
Leave a comment