A E I O U by CodeChum-Solution | AskTheCode

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;
}
46 views0 comments

Recent Posts

See All

Solubility - CodeChef Solution in Java and C++| AskTheCode

CodeChef May Long Challenge Solution | Solubility (SOLBLTY) solution | AskTheCode Solubility (SOLBLTY) solution Problem: Suppose for a unit rise in temperature, the solubility of sugar in water increa

Valid Paths CodeChef Solution in C++ | AskTheCode

CodeChef May Long Challenge Solution | Valid Paths (VPATH) solution | AskTheCode Valid Paths (VPATH) CodeChef solution Problem: You are given a tree with N nodes numbered from 1 to N. A set S of nodes