value returning function problem

I have tried this program & ran it like 10 times on the compiler on mindtap yet it still does not give me full credit.

here's the code
#include <iostream>

using namespace std;

bool isVowel(char letter);

int main()
{
char userChar;

cout << "Please enter a character: ";
cin >> userChar;

if (isVowel(userChar))
cout << userChar << " is a vowel" << endl;
else
cout << userChar << " is not a vowel" << endl;

return 0;
}

bool isVowel(char letter) {
switch (letter) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
return true;
default:
return false;
}
}
What if you entered "y"?

Edit: More significantly, what if you entered 'A'?
Last edited on
#include <iostream>

using namespace std;

bool isVowel(char letter);

int main()
{
char ch;

cout << "Please enter a character: ";
cin >> ch;

if (isVowel(ch))
cout << ch << " is a vowel" << endl;
else
cout << ch << " is not a vowel" << endl;

return 0;
}

bool isVowel(char letter) {
switch (letter) {
case 'A':
case 'a':
case 'E':
case 'e':
case 'I':
case 'i':
case 'O':
case 'o':
case 'U':
case 'u':
return true;
default:
return false;
}
I changed it to this & still gives me 33%
Last edited on
'Y' and 'y' are vowels too. You can also just do:
1
2
if (isVowel(std::tolower(ch))
   //do stuff 


If you do that, you don't need to check capital letters anymore.
that's error prone.
may do letter = std::tolower(letter); inside the `isVowel()' function instead.

> 'Y' and 'y' are vowels too
yes, beyond all doubt, young man.
┬┐what do we do with w?


by the way, I suggest we continue the discussion in the original thread http://www.cplusplus.com/forum/beginner/225724/
(because it was created earlier, and beginner section seems more appropriated)
Topic archived. No new replies allowed.