Help with arrays

Hello my fellow nerd lingers;). I am having trouble with one of my projects dealing with arrays. The assignment is to have the user write a phrase and then list the number of words as well as the number of each letter used in the phrase. I have started it and, although it is a bit sloppy, I need help with minor improvements on making it compile and run correctly. Here is the code I have so far.

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
 #include <iostream>
using namespace std;


int main()
{

	int in_word = false;
	int count[100];
	char array[100];
	int word_count = 0;
	char ch;
	char low_case;
	int char_count[26];
	int i;

	cout << "Please enter a sentence\n";
	cin.getline(array, 100);

	for (i=0; i<26; i++)
	  char_count[i] = 0;

	while ('\n' != (ch = cin.get()))
	{
	  if (' ' == ch || '\n' == ch || 't' == ch)
		in_word = false;
	  else if (in_word == false)
	  {
	  	in_word = true;
		word_count++;
	  }
	  low_case = tolower ( ch);
         char_count[int(low_case) - int('a')]++;

	cout << count << "words" <<endl;

	for (i=0; i<26; i++)
	{
	  if (count[i] !=  0)
		cout <<count[i] << " " << char(i + 'a') <<endl;
	}
	}
}
Last edited on
Topic archived. No new replies allowed.