Write a program that prompts the user to input a sequence of characters and outputs the number of vowels and the number of consonants.
#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;
}
Comments
Leave a comment