For loop error

I have to write a program in which you enter 20 characters and the program counts how many times each vowell is introduced. This is what I have:
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
#incluof <stdio.h>

int main ()
{
	int a, e, i, o, u, x;
	char letter;

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

	for (x = 0; x <= 20; x++)
	{
		printf("Enter character: ", x);
		scanf("%c", & letter);

		if (letter == 'a')
		{a = a + 1;}

		else if (letter == 'e')
		{e = e + 1;}

		else if (letter == 'i')
		{i = i + 1;}

		else if (letter == 'o')
		{o = o + 1;}

		else if (letter == 'u')
		{u = u + 1;}

		else
		{}
		}

	printf("Number of 'a': %d\n", a);
	printf("Number of 'e': %d\n", e);
	printf("Number of 'i': %d\n", i);
	printf("Number of 'o': %d\n", o);
	printf("Number of 'u': %d\n", u);

	fflush (stdin);
	getchar ();
	return 0;
	}


Everything seems fine, but, when it gets to the for, it only allows to introduce the characters when the variable in the for loop is an odd number.

I would like to know how I could fix this. Thanks, guys!
When you press enter, the '\n' in entered into stdin's buffer, so the next time it reads it reads that and runs the loop on it. You might want to simply check for a newline character and not increment the variable in the for loop if that's the case.
And also, don't fflush() input streams! You get undefined behavior.
Topic archived. No new replies allowed.