Write a program that prompts the user to input a sequence of characters and outputs the number of vowels.
(Use the function isVowel written in Programming Exercise 2.)
Your output should look like the following:
There are # vowels in this sentence.
... where # is the number of vowels.
#include<bits/stdc++.h>
using namespace std;
int isVowel(string s)
{
int f=0;
char ch;
for(int i=0;i<s.length();i++)
{
ch=toupper(s[i]);
if(ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')
{
f=f+1;
}
}
return f;
}
int main()
{
string s;
cout<<"Enter a string ";
cin>>s;
cout<<"There are "<<isVowel(s)<<" vowels in this sentence.";
}
Comments
Leave a comment