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;
}
|