Character Count Program Issue

Edit: solved.
Last edited on
Hi Zelotic

Are you aware that each case should have break?
and its good idea to use default if all other cases don't fit.
Lines 9-10: Why are you zeroing the array each time though the loop?

Lines 28-32: You want to print the totals AFTER the loop. Move these lines after line 35.

@xxvms - In this case, the OP wants each listed case to fall though to the last one.



Last edited on
Hello again,

I updated the topic to reflect MULTIPLE issues I began having after the rest of the code was finished.

@AbstractionAnon I took your advice and now I am receiving no print at all.
Last edited on
1
2
3
while(!input.eof()) {
	for (int i = 0; i < 256; ++i)
		list[i] = 0;

Why are you resetting the array back to zero each time through the loop? You should only need to initialize the elements once, when you define the array. Also why is the array 256 characters in size?

By the way you could initialize the variable when you define it without the loop.

long list[256] {0};

1
2
3
4
5
	for (int i = 32; i < 127; ++i)
	{
		if (list[i] > 0)
			cout << "A vowel occured " << list[i] << " times." << endl;
	}

Shouldn't you be doing this after the entry loop, not every time through the entry loop?

Where are you "totaling" any variables?

By the way in a C++ program you should use C++ style casts instead of the C style cast:
1
2
//case 'Y': list[int(letter)]++;
case 'Y': list[static_cast<int>(letter)]++;



Topic archived. No new replies allowed.