Answer to Question #183011 in C++ for Vincenzo Santoro

Question #183011

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.



1
Expert's answer
2021-04-26T15:02:10-0400
#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;    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS