[Solved] Count Vowel with C++

Count Vowel: In the Mini project 8th module is to find the number of vowel letters in a word(consider both uppercase and lowercase). Rita allotted this function to Patrick.
Help Patrick to write a program to find the number of vowel letters in a word.
 

Function Specification:
int findNumberOfVowels(char);
 

Input format :
Input consists of a string.
 

Output format :
Output consists of an integer saying the number of vowel in the given word.

Refer sample Input and Output for further specifications.

[ All text of bold corresponds to input and the rest corresponds to output. ]


Sample Input and Output format :

Enter the word :

Alice

Count of vowels in Alice is 3
Function Definitions:

int findNumberOfVowels (char *) 

Solution

#include <iostream>
using namespace std;

int findNumberOfVowels(char *word)
{
    int count = 0;
    for (int i = 0; word[i] != '\0'; i++)
    {
        if (word[i] == 'a' || word[i] == 'e' || word[i] == 'i' || word[i] == 'o' || word[i] == 'u' || word[i] == 'A' || word[i] == 'E' || word[i] == 'I' || word[i] == 'O' || word[i] == 'U')
        {
            count++;
        }
    }
    return count;
}

int main()
{
    char word[100];
    cout << "Enter the word :\n";
    cin >> word;
    cout << "Count of vowels in " << word << " is " << findNumberOfVowels(word) << endl;
    return 0;
}

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *