Monday, May 5, 2008

program to count vowel alphabets using c++

Write a program that will count the number of A's, E's, I's, O's and U's in a sentence.

PROGRAM:


#include <iostream.h>

#include <conio.h>

#include <ctype.h>


void main() {

clrscr();

int a=0,e=0,i=0,o=0,u=0;

char ch;

cout<<"Program to count number of a,e,i,o,u in a sentence \n";

cout<<"Enter your sentence: \n";

while((ch=getche())!='\r') {

switch(tolower(ch)) {

case 'a': a++;

break;

case 'e': e++;

break;

case 'i': i++;

break;

case 'o': o++;

break;

case 'u': u++;

break;

}//end of switch

}//end of while

cout<<"\nTotal Number of a: "<<a;

cout<<"\nTotal Number of e: "<<e;

cout<<"\nTotal Number of i: "<<i;

cout<<"\nTotal Number of o: "<<o;

cout<<"\nTotal Number of u: "<<u;

getch();

}//end of program

No comments: