Help for vowels!


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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
 /*The program prompts the user to enter a sentence, 
count the number of vowels, display the length of the sentence and count the number of each vowels.*/

#include<iostream>

using namespace std;

int main()
{
	char sentence=' ';
	int count=0,count1=0,count2=0,count3=0,count4=0;
	
	cout<<"Enter a sentence: ";
	cin.get(sentence);
	
	cout<<"Vowels: ";
	while (sentence!='\n')
	{
		cin.get(sentence);
		switch(sentence)
		{
			case 'A':;
				count++;
				break;
			case 'a': ;
				count++;
			case 'E':;
				count1++;
				break;
			case 'e':;
				count1++;
				break;
			case 'I':;
				count2++;
				break;
			case 'i':;
				count2++;
				break;
			case 'O':;
				count3++;
				break;
			case 'o':;
				count3++;
				break;
			case 'U':;
				count4++;
				break;
			case 'u':;
				count4++;
				break;
			}
			
		}
	cout<<"There are "<<count<<" a's, "<<count1<<" e's, "
	<<count2<<" i's, "<<count3<<" o's, and "<<count4<<" u's in the sentence.";
	
	return 0;
}


The output should have 5 a's, 5 e's, 2 i's, 2 o's, and 0 u's.
What help do you need?

aside from...
1
2
3
4
5
6
7
8
case 'A':
case 'a':
    ++count;
    break;
case 'E':
case 'e':
    ++count1;
    break;

This doesn't fix the problem, but should help you debug it.

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<iostream>

using namespace std;

int main()
{
	char sentence=' ';
	int count=0,count1=0,count2=0,count3=0,count4=0;
	
	cout<<"Enter a sentence: ";
	cin.get(sentence);
	
//	cout<<"Vowels: ";
	while (sentence!='\n')
	{
// Test
	cout << sentence <<" There are "<<count<<" a's, "<<count1<<" e's, "
	<<count2<<" i's, "<<count3<<" o's, and "<<count4<<" u's in the sentence." << endl;

		cin.get(sentence);
		switch(sentence)
		{
			case 'A':;
				count++;
				break;
			case 'a':;
				count++;
			case 'E':;
				count1++;
				break;
			case 'e':;
				count1++;
				break;
			case 'I':;
				count2++;
				break;
			case 'i':;
				count2++;
				break;
			case 'O':;
				count3++;
				break;
			case 'o':;
				count3++;
				break;
			case 'U':;
				count4++;
				break;
			case 'u':;
				count4++;
				break;
			}
// Test
	cout << sentence <<" There are "<<count<<" a's, "<<count1<<" e's, "
	<<count2<<" i's, "<<count3<<" o's, and "<<count4<<" u's in the sentence." << endl<< endl;
		}
	cout<<"There are "<<count<<" a's, "<<count1<<" e's, "
	<<count2<<" i's, "<<count3<<" o's, and "<<count4<<" u's in the sentence.";
	
	return 0;
}
Here is the correct program, I've bolded what I've changed into your original program:
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<iostream>

using namespace std;

int main()
{
	char sentence=' ';
	int count=0,count1=0,count2=0,count3=0,count4=0;
	
	cout<<"Enter a sentence: ";
	cin.get(sentence);
	
	cout<<"Vowels: ";
	while (sentence!='\n')
	{
		switch(sentence)
		{
			case 'A':;
				count++;
				break;
			case 'a': ;
				count++;
                                break;
			case 'E':;
				count1++;
				break;
			case 'e':;
				count1++;
				break;
			case 'I':;
				count2++;
				break;
			case 'i':;
				count2++;
				break;
			case 'O':;
				count3++;
				break;
			case 'o':;
				count3++;
				break;
			case 'U':;
				count4++;
				break;
			case 'u':;
				count4++;
				break;
			}
		cin.get(sentence);

		}
	cout<<"There are "<<count<<" a's, "<<count1<<" e's, "
	<<count2<<" i's, "<<count3<<" o's, and "<<count4<<" u's in the sentence.";

return 0;
}
Topic archived. No new replies allowed.