Help!!

I need help for a program that allows the user to enter a statement and outputs statistics; number of vowels, number of constants, percentage of vowels and constants, number of words, number of punctuation characters
And where is your problem?
While you should be writing your own code, and posting problems on the board, I see you're new. Nobody really wants to write your assignments/homework for you - they want to be presented with a problem, what you've tried, and a code snippet and any errors/challenges you're running into.

I started on this for you, a bit. It's really a terrible way to approach the problem, but I figure you're very new to programming and didn't want to get too complex. Additionally, I didn't really scrutinize it for logic errors, but it does compile:

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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream> 
#include <string>
using namespace std;

void parseStatement( string &suppliedStatement, int &numberOfVowels, int &numberOfConsonants, int &numberOfPunctuationCharacters );

int main()
{
	string userStatement;
	int numberOfVowels = 0;
	int numberOfConsonants = 0;
	int numberOfPunctuationCharacters = 0;

	cout << "Please enter a statement: ";
	getline( cin, userStatement );
	parseStatement( userStatement, numberOfVowels, numberOfConsonants, numberOfPunctuationCharacters );

	cout << "Number of Vowels: " << numberOfVowels << endl;
	cout << "Number of Consonants: " << numberOfConsonants << endl;
	cout << "Number of Punctuation: " << numberOfPunctuationCharacters << endl;

	return 0;
}

void parseStatement( string &suppliedStatement, int &numberOfVowels, int &numberOfConsonants, int &numberOfPunctuationCharacters )
{
	for( unsigned int i = 0; i < suppliedStatement.length(); i++ )
	{
		switch( suppliedStatement[ i ] )
		{
		case 'a':
		case 'e':
		case 'i':
		case 'o':
		case 'u':
			numberOfVowels++;
			break;
		case '.':
		case '!':
		case ',':
		case '?':
		case ';':
			//ect
			numberOfPunctuationCharacters++;
			break;
		case 'b':
		case 'c':
		case 'd':
		case 'f':
		case 'g':
		case 'h':
		case 'j':
		case 'k':
		case 'l':
		case 'm':
		case 'n':
		case 'p':
		case 'q':
		case 'r':
		case 's':
		case 't':
		case 'v':
		case 'w':
		case 'x':
		case 'y':
		case 'z':

		case 'B':
		case 'C':
		case 'D':
		case 'F':
		case 'G':
		case 'H':
		case 'J':
		case 'K':
		case 'L':
		case 'M':
		case 'N':
		case 'P':
		case 'Q':
		case 'R':
		case 'S':
		case 'T':
		case 'V':
		case 'W':
		case 'X':
		case 'Y':
		case 'Z':
			numberOfConsonants++;
			break;
		
		};
	}
}


It could have been done by simply converting the character you're currently looking at into an integer and comparing it to an integer range (Look at an ASCII chart for the corresponding character decimals) and then increment the correct variable. But w/e - lots of ways to approach it.
Last edited on
Topic archived. No new replies allowed.