Help! my program skipped the cin.

The compiler asked for first answer of student but skipped the others in the first for loop.

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
  #include <iostream>

using namespace std;

int main ()
{
	int wrong = 0;
	int bingo = 0;
	int student[20];
	int answer[20]={'A','D','B','B','C','B','A','B','C','D','A','C','D','B','D','C','C','A','D','B'};

	for(int i = 1; i <= 20; i++)
	{
		cout << "Please enter the anser for question number " << i << ".(Only accept A,B,C and D)" << endl;
		cin >> student[i];
	}
	
	for(int i = 1; i <= 20; i++)
	{
		if (student[i] == answer[i])
		{
			bingo = bingo + 1;
		}
		else
		{
			wrong = wrong + 1;
		}
	}

	if(bingo >= 15)
	{
		cout << "You pass!" << endl;
	}
	else
	{
		cout << "You fail!" << endl;
	}

	cout << "The total number of correctly answered questions is: " << bingo << endl;
	cout << "The total number of incorrectly answered questions is: " << wrong << endl;

	for(int i = 1; i <= 20; i++)
	{
		if (student[i] != answer[i])
		{
			cout << "The wrong questions are: " << student[i] << endl;
		}
	}

	system("pause");
	return 0;
}
Last edited on
Looks like you're trying to store a character "Only accept A,B,C and D" in a type "int". Try changing line 9 to: char student[20];
Thank you, sMav! It work! <3
Topic archived. No new replies allowed.