Question: #include #include using namespace std; int main ( ) { char ch; int vowels = 0 , consonants = 0 , others = 0 ;

#include
#include
using namespace std;
int main(){
char ch;
int vowels =0, consonants =0, others =0;
int a_count =0, e_count =0, i_count =0, o_count =0, u_count =0;
int total_letters =0;
cout << "Enter text: ";
while (cin >> noskipws >> ch){
if (ch =='.'|| ch =='!'){
break;
}
if (isalpha(ch)){
ch = tolower(ch);
total_letters++;
if (ch =='a'){
vowels++;
a_count++;
} else if (ch =='e'){
vowels++;
e_count++;
} else if (ch =='i'){
vowels++;
i_count++;
} else if (ch =='o'){
vowels++;
o_count++;
} else if (ch =='u'){
vowels++;
u_count++;
} else {
consonants++;
}
} else if (!isspace(ch)){
others++;
}
}
cout << "Your sentence has "<< total_letters <<" letter(s)."<< endl;
cout << "Number of a's: "<< a_count << endl;
cout << "Number of e's: "<< e_count << endl;
cout << "Number of i's: "<< i_count << endl;
cout << "Number of o's: "<< o_count << endl;
cout << "Number of u's: "<< u_count << endl;
cout << "Number of consonants: "<< consonants << endl;
cout << "Number of other characters: "<< others << endl;
if (total_letters >0){
double vowel_percentage =(static_cast(vowels)/ total_letters)*100;
cout << "Vowels make up "<< vowel_percentage <<"% of the sentence." << endl;
} else {
cout << "Vowels make up 0% of the sentence." << endl;
}
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!