C++ program to count the number of vowels in a string | CodeChum Solutions | CPP programming
Problem:
We’ve been doing some research on the contents of text messages sent by users all around the globe. Our current dilemma is determining how many vowels do users use on average in a regular text message. If you could find a way to count the number of vowels, we’ll take care of finding the average.
Input Format:
A single line containing a string.
Output Format:
A single line containing the number of vowels found in the string.
Input Sample:
Hello·World!
Output Sample:
3
Code:
// A E I O U by CodeChum
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
getline(cin,s);
int i = 0, count = 0;
while(s[i]){
if (s[i] == 'A' || s[i] == 'a' || s[i] == 'E' || s[i] == 'e' || s[i] == 'I' || s[i] == 'i' ||
s[i] == 'O' || s[i] == 'o' || s[i] == 'U' || s[i] == 'u'){
count++;
}
i++;
}
cout << count << endl;
return 0;
}
Comments