Answer to Question #183012 in C++ for Vincenzo Santoro

Question #183012

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.


1
Expert's answer
2021-04-27T07:15:53-0400
#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.";
}

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
APPROVED BY CLIENTS