Sep 7, 2015 at 4:15pm UTC
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 Sep 7, 2015 at 4:18pm UTC
Sep 7, 2015 at 4:41pm UTC
i guess the logic :D, cause i would just had the main concept and done it in c#
Sep 7, 2015 at 4:45pm UTC
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.
Sep 7, 2015 at 4:58pm UTC
so you mean, that i check if(string[i] == a || string[i] == e|| string[i] == i etc.) to increase the counter
Sep 7, 2015 at 6:40pm UTC
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;
}