Activity 7
Write a program that asks the user to enter a lowercase letter and determines whether or not the letter is a vowel. If the user enters a vowel, print “This is a vowel”, if the user enters a consonant, print “This is a consonant”. If the user enters the letter ‘y’, print “This is sometimes a vowel”. If the user enters anything other than a lowercase letter, print “Invalid input”.
活动7
编写一个程序,要求用户输入小写字母并确定该字母是否为元音。如果用户输入一个元音,则打印“这是一个元音”;如果用户输入一个辅音,则打印“这是一个辅音”。如果用户输入字母“ y”,则打印“有时是元音”。如果用户输入除小写字母之外的其他任何内容,请打印“无效输入”。
#include <iostream> using namespace std; int main() { char c; cout<<"Please input a letter: "; cin>>c; if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u') { cout<<"This is a vowel"<<endl; } else if(c=='y') { cout<<"This is sometimes a vowel"<<endl; } else if(c>='a' && c<='z') { cout<<"This is a consonant"<<endl; } else { cout<<"Invalid input"<<endl; } return 0; }