count vowels in a string. how

umm, so, erm, i simply dont know how to count vowels in c++ :D. i have a string entered via console and i need to count all vowels.
Last edited on
Do you really mean "in C++": http://www.cplusplus.com/reference/algorithm/count_if/
OR
the logic of "how to count"?
i guess the logic :D, cause i would just had the main concept and done it in c#
The logic should be the same in every language.

You have a counter that has value of 0 at start.
You look at each element in the set. If an element fulfills a condition (is a vowel), then you increment the counter.
Once you have checked all the elements, you will have the answer in the counter.
so you mean, that i check if(string[i] == a || string[i] == e|| string[i] == i etc.) to increase the counter
The code Is like thsi

#include<iostream>

using namespace std;


int main(){
string n;
int counter=0;
cout<<"Enter A string ";
getline(cin,n);

for(int i=0;i<n.length();i++){
if(n[i]=='a' || n[i]=='e' || n[i]=='i' || n[i]=='o'
|| n[i]=='u' || n[i]=='A' || n[i]=='E'
|| n[i]=='I' || n[i]=='O' || n[i]=='U' ){
counter++;
}
}

cout<<"Total Number Of Vowels are "<<counter<<endl;

}
Topic archived. No new replies allowed.