Program to count individual vowels

Feb 11, 2013 at 6:34pm
Hello all,

I need to write a program that reads in 1 text character at a time and counts the number of individual vowels. It was also suggested that I use a while loop, with 5 separate counters. Also, when a period or question mark appears in the input text, the program prints the number of vowels and stops. I tried making a while loop with 5 'if' statements, that (i thought) would increment each vowel counter, but the program would never terminate. Should I use a do-while loop, using 5 if statements to increment the counters, and end it with while (c != '.' || c!= '?');

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
using namespace std;
int main() 
{
double a;
double e;
double i;
double o;
double u;
char c;

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

cout << "Enter text: ";
cin >> c;

while (c != '.' || c != '?')
{
if (c == 'a')
{a++;}
if (c == 'e')
{e++;}
if (c == 'i')
{i++;}
if (c == 'o'}
{o++;}
if (c == 'u'}
{u++;}

cin >> c;
}
return (0);
cout << a++;
cout << e++;
cout << i++;
cout << o++;
cout << u++;
}


This is a tentative code which compiles, but doesn't seem to terminate.
Any help is appreciated. Thanks
Last edited on Feb 11, 2013 at 9:36pm
Feb 11, 2013 at 7:13pm
Post the code so we can see it and guide you in the right direction....
Topic archived. No new replies allowed.