/* Drivers license exam program to grade a 20 question test *Put all the correct answers in 1 array, all the users answers in another *compare arrays for # of correct answers **student must get 15 out of 20 to pass *tells student in this order **Did they pass **total number of correct questions **total number of incorrect questions **list showing the numbers of the questions that were wrong */ /* ***ANSWERS //can only accept ABC or D as an answer 1. B 2. D 3. A 4. A 5. C 6. A 7. B 8. A 9. C 10. D 11. B 12. C 13. D 14. A 15. D 16. C 17. C 18. B 19. D 20. A */ #include #include #include using namespace std; int main() { const int QUESTIONS = 20; //1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 char correctAnswers[QUESTIONS] = {'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D', 'B', 'C', 'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A'}; //number of questions is 20 in the test, and then we store the answers in an array char studentAnswers[QUESTIONS]; bool badEntry = false; int answeredCorrectly = 0; //we use char right & wrong to compare against since if we try to compare against 'A' it'll compare incorrectly const char wrong = 'X', right = '.', A = 'A', B = 'B', C = 'C', D = 'D'; //now we use a for loop to go through the questions and store whether the answer was right or wrong /*for (int x = 0; x < QUESTIONS;) { cout << "Please enter the answer for question #" << (x + 1) << endl; cin >> studentAnswers[x]; if (studentAnswers[x] != A || B) { badEntry = true; while (badEntry = true) { cout << "Invalid entry, please enter A, B, C, or D" << endl; cin >> studentAnswers[x]; if (studentAnswers[x] == A || B) badEntry = false; } } }*/ //here's where we check for an invalid entry //stores the answer and replaces the students answer with whether it was right or wrong if (studentAnswers[x] == correctAnswers[x]) { answeredCorrectly++; studentAnswers[x] = '.'; } else studentAnswers[x] = 'X'; x++; } //now that we have cycled through all the questions and gotten the answers, heres the info we have //questions have been entered //judged whether they were right or wrong //stored Y or N in the studentAnswer array so we can tell them which questions were wrong //now we just output all of it /* **Did they pass **total number of correct questions **total number of incorrect questions **list showing the numbers of the questions that were wrong */ //need to use strcmp to compare the char arrays if (answeredCorrectly >= 15) cout << endl << "Congratulations, you passed!" << endl << endl; if (answeredCorrectly < 15) cout << endl << "You failed, better work on those pipe laying skills!" << endl << endl; cout << "You got " << answeredCorrectly << " questions right." << endl; cout << "You got " << (20 - answeredCorrectly) << " questions wrong." << endl << endl; cout << "The questions you got wrong were" << endl; for (int y = 0; y < QUESTIONS; y++) { if (studentAnswers[y] == wrong) cout << "Question " << (y + 1 ) << ": " << studentAnswers[y] << endl; //if (studentAnswers[y] = 'N') //cout << "Question " << (y + 1) << endl; } cout << "Please press any key then hit enter to exit" << endl; cin >> answeredCorrectly; }