Vector Outputs Alien Language

Program:
I have 2 arrays: 1 for the correct answers to a quiz, 1 for the user. I then have a vector to hold the incorrect answers.

It keeps outputting what looks like alt characters, and I have no idea why.

Here is the code:

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

int main()
{
	const char a1[]={'a','d','b','b','c','b','a','b','c','d','a','c','d','b','d','c','c','a','d','b'};
	char a2[20];
	int i=0;
	int incorrect=0;
	vector<char> incorrectQuestions;

	cout<<"Drivers License Exam:\n";
	for(i=0;i<20;i++)
	{
		cout<<"Please enter the answer to question #"<<i+1<<"\n";
		cin>>a2[i];
		while(a2[i]!='a'&&a2[i]!='b'&&a2[i]!='c'&&a2[i]!='d'
			)
		{
			cout<<"Error: Please enter either a, b, c, or d:\n";
			cin>> a2[i];
		}
		if(a1[i]!=a2[i])
		{
			incorrect++;
			incorrectQuestions.push_back(i);
		}
	}

	if(incorrect>5)
	{
		cout<<"Sorry.. You failed the test.\n";
		cout<<"The number of correct answers are: "<<(20-incorrect)<<"\n";
		cout<<"The number of incorrect answers are: "<<incorrect<<"\n";
		cout<<"The incorrect questions are:\n";
		int numValues=incorrectQuestions.size();
		for(i=0;i<numValues;i++)
		{
			cout<<incorrectQuestions[i]<<"\n";
		}
	}
	else
	{
		cout<<"You passed the test!.\n";
		cout<<"The number of correct answers are: "<<(20-incorrect)<<"\n";
		cout<<"The number of incorrect answers are: "<<incorrect<<"\n";
		cout<<"The incorrect questions are:\n";
		int numValues=incorrectQuestions.size();
		for(i=0;i<numValues;i++)
		{
			cout<<incorrectQuestions[i]<<"\n";
		}
	}
	system("Pause");
	return 0;
}
Line 27: You push_back i, which is an int, but your vector is declared a vector of chars. Change line 11 to a vector of ints.
Topic archived. No new replies allowed.