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
|
#include <iostream>
#include <cctype>
using namespace std;
int main()
{
char exam_answers[20] = {'B','D','A','A','C','A','B','A','C','D','B','C','D','A','D','C','C','B','D','A'};
char users_answers[20];
int num_wrong = 0, num_right = 0;
cout<<"Driver's License Exam Grader\n";
for(int i = 1; i<=20; i++)
{
char validate;
cout<<"Enter your answer for question "<<i<<endl;
cin>>validate;
validate = toupper(validate);
if(validate != 'A' && validate != 'B' && validate != 'C' && validate != 'D')
{
cout<<"Invalide input. Eneter only:A, B, C, or D. Try again.\n";
--i;
continue;
}
exam_answers[i] = validate;
}
for(int j=0; j<=20;j++)
{
if(exam_answers[j] != users_answers[j])
{
cout<<"Answer "<<j<<" is incorrect.\n";
num_wrong++;
}
}
num_right = 20 - num_wrong;
cout<<"Results (miniumum 15 correct to pass) :\n";
cout<<"You got "<<num_right<<" correct.\n";
cout<<"You missed "<<num_wrong<<".\n";
if(num_right<15)
{
cout<<"You've failed.\n";
}
else
{
cout<<"You've Passed.\n";
}
}
| |