Input sentence and count total number of vowels present in it in C++
String Methods - Question 1
In this question, we will see how to input a sentence and count the total number of vowels present in it in C++ programming. To know more about string methods click on the string methods lesson.
Q1) Write a program in C++ to input a sentence and count the total number of vowels present in it.
Program
#include <iostream>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
using namespace std;
int main()
{
char s[100];
char ch;
int vc=0,i;
cout<<"Enter a sentence\n";
gets(s);
for(i=0; i<strlen(s); i++)
{
ch=tolower(s[i]);
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')
{
vc++;
}
}
cout<<"Total vowels = "<<vc;
return 0;
}
Output
Enter a sentence I am learning C++ programming Total vowels = 8