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 58 59 60 61 62 63 64 65 66 67 68
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
const int SIZE = 20;
//characters for loop that tests if A B C or D
char A, B, C, D;
//correct answer key
char correctAnswers[SIZE] = {'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D', 'B', 'C', 'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A'};
//array for user answers
char userAnswers[SIZE];
//array to store if a question is right (R) or wrong (W)
char Correctness[SIZE];
int sum = 0;
int index, count; //counter variables
int finalcount;
cout << "Driver's License Exam Grader" << endl;
//for loop takes in user selection
for (index = 1; index < 21; index++)
{
cout << "Enter your answer for question " << index << endl;
cin >> userAnswers[index];
//if loop to compare users answers and answer key
if (userAnswers[index] != correctAnswers[index])
{
//if user enters incorrect answer, store W
Correctness[index] = 'W';
}
else
{
//if user answer is correct, store R and and 1 to sum.
Correctness[index] = 'R';
}
}
//this for loop is to read the "correctness" array and output Right or Wrong accordingly
for (index = 1; index < 21; index++)
{
//if correctness is W, meaning is it Wrong, output that it is incorrect
//no output here if correct
if (Correctness[index] == 'W')
{
cout << "Answer " << index << " is incorrect." << endl;
}
else
{
sum += 1;
}
}
finalcount = 20 - sum;
//output final results
cout << "Results (minimum 15 correct to pass):" << endl;
cout << "You got " << sum << " correct. " << endl;
cout << "You missed " << (20 - sum) << "." << endl;
if (sum >= 15)
{
cout << "You've passed!" << endl;
}
else
{
cout << "You've failed." << endl;
}
}
|