第一种if:
char ch;
char ch1[5] = { 'a','e','i','o','u' };
cout << "请输入一个字母:";
cin >> ch;
if (ch<65||(ch>90&&ch<97)||ch>122)
{
cout << "不是字母!";
return 0;
}
for (int i = 0; i < 5; i++) {
if (ch == ch1[i]) {
cout << ch << "是元音" << endl;
return 0;
}
else if (ch - 32 == ch1[i]) {
cout << ch << "是元音" << endl;
return 0;
}
}
cout << ch << "是辅音" << endl;
return 0;
第二种switch:
char ch;
cout << "请输入一个字母:";
cin >> ch;
if (ch<65||(ch>90&&ch<97)||ch>122)
{
cout << "不是字母!";
return 0;
}
switch (ch)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
cout << ch << "是元音" << endl;
break;
default:
cout << ch << "是辅音" << endl;
break;
}