Answer to Question #278180 in C++ for develskie

Question #278180

Write a program that prompts the user to input a sequence of characters and outputs the number of vowels and the number of consonants.


1
Expert's answer
2021-12-10T07:17:53-0500
#include<iostream>
#include<string>

using namespace std;

int main()
{
	string input;
	cout<<"Please, enter a sequence of characters:\n";
	getline(cin,input,'\n');
	char c;
	int vowels=0;
	int consonants=0;
	for(int i=0;i<input.size();i++)
	{
		c=tolower(input[i]);
		if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
		{
			vowels++;
		}
		else if(isalpha(input[i]))
		{
			consonants++;
		}
	}	
	cout<<"The number of vowels is "<<vowels
		<<"\nThe number of consonants is "<<consonants;
	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog