Count Vowels in a String in C++

Program to count and print the number of vowels in a given string.

Source code :

#include<iostream>

using namespace std;


int main(){

    char str[10];
    int vow=0;
    cout<<"Enter a String : "; // say hello
    cin>>str;

    for(int i=0;str[i]!='\0';i++){


        if(str[i]=='a'
            ||str[i]=='A'
            ||str[i]=='e'
            ||str[i]=='E'
            ||str[i]=='i'
            ||str[i]=='I'
            ||str[i]=='o'
            ||str[i]=='O'
            ||str[i]=='u'
            ||str[i]=='U'){

            vow++;
        }

    }
    cout<<"\nNumber of vowels:"<<vow;
    return 0;
}

Output :

Enter a String : hello
Number of vowels: 2

Output :


                

Comments :