// dosen't allow or
if ( Letter = 'a' || Letter = 'A' || Letter = 'E' || Letter = 'e' || Letter = 'I' || Letter = 'i' || Letter = 'O' || Letter = 'o' || Letter = 'U' || Letter = 'u')
{
cout << " This is a vowel " << endl;
}else{
cout << " This letter is a consonant " << endl;
}
switch(Letter)
{
case'a':case'A':case'e':case'E':case'i':case'I':case'o':case'O':case'u':case'U':
cout << "This is a vowel"<< endl;
break;
default:
cout<< "This letter is a consonant" << endl;
}
You can also do like this: int i,check;
char al,vow[10]={'A','a','E','e','I','i','O','o','U','u'};
cout<<"Enter an alphabet:";
cin>>al;
for(i=0;i<10;i++)
{
if(al==vow[i])
{
check=1;
break;
}
else
check=0;
}
if(check==1)cout<<"\nThis letter is a vowel.";
else cout<<"\nThis letter is a consonant.";
I suggest using tolower to avoid checking both upper and lower case letters, e.g:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
bool isvowel(int c) {
c = std::tolower(c);
return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
}
int main() {
//...
if (isvowel(c)) {
cout << "This is a vowel" << endl;
} elseif (std::isalpha(c)) {
cout << "This is a consonant" << endl;
} else {
cout << "This is not a letter" << endl;
}
}
My teacher says that this is easy I don't think so.
The ancient Egyptians wrote in hieroglyphics, in which vowels sounds are not represented, only consonants. Is written English generally understandable without vowels? To experiment, write a function isvowel( ) that tests whether or not a character is a vowel. Write a function in a program that reads the standard input file (keyboard) and write to the standard output file (screen), deleting all vowels.
I am sorry, I would have to agree with your teacher regarding this problem. You have been given a few good options on here showing how you can solve this problem very trivially.
#include <iostream> // For access to cout, cin, endl
#include <string> // For access to string class
usingnamespace std; // To avoid having to prefix std:: onto cout, cin, etc...
bool isvowel( char ch ) {
// Lots of examples above
}
string read_input() {
// Have this function read from standard input a string (using cin)
// and return the string read.
}
void output( string const& s ) {
// Pass in the string you read from read_input.
// For each character in the string:
// if character is a consonant (ie, call isvowel)
// output the character to standard output (using cout)
}
int main() {
// Get input (ie, call read_input )
// Output answer (ie, call output)
return 0;
}