For this, it is supposed to read in the answers entered by the user and compare it to the array containing the correct answers. It reads them in, but I can't get it to compare in the QuestonsCorrect function. Any help is greatly appreciated!
Code:
#include <iostream> // include standard I/O library
#include <string> // include C++ string class handling
#include <iomanip> // include input/output function
#include <cmath> // include C++ math function
#include <cstdlib> // include standard utilities
using namespace std;
/* ========================================================================== */
/* GLOBAL CONSTANTS */
const int NUMBER_OF_ANSWERS = 20;
const int CORRECT_TO_PASS = 15;
int numCorrect = 0;
int numIncorrect = 0;
/* ========================================================================== */
/* FUNCTION PROTOTYPES */
void PrintIntro();
int AskForScores();
void QuestionsCorrect();
void PassExam ();
void QuestionList();
void PrintClosing();
/* ========================================================================== */
typedef char Answers [NUMBER_OF_ANSWERS];
int main () //begin main function
{
int correctAnswer [NUMBER_OF_ANSWERS];
//Answers correct[] = {"BDAACABACDBCDCCBDA"};
char correct[] = {"BDAACABACDBCDCCBDA"};
PrintIntro();
AskForScores();
PassExam();
QuestionList();
PrintClosing();
}
void PrintIntro()
{
/* print an overall output title for program; print overall title for output
set width of each line*/
cout << setw (47) << "=====================================" << endl;
cout << setw (40) << "DMV Driver's License Exam" << endl;
cout << setw (47) << "=====================================" << endl
<< endl;
}
int AskForScores()
{
int i;
char answerChoices[NUMBER_OF_ANSWERS];
for (i=0; i<NUMBER_OF_ANSWERS; i++)
{
cout << "Please enter answer " << i+1 << " in CAPITAL LETTERS." << endl;
cin >> answerChoices[i];
while (answerChoices[i] < 'A' || answerChoices[i] > 'D')
{
cout << "Invalid input. Please re-enter answer" << i+1 << " in CAPITAL LETTERS." << endl;
cin >> answerChoices[i];
}
}
cout << answerChoices << endl;
return 0;
}
int QuestionsCorrect (char answerChoices[], char i, char correct[])
{
for(int i=0; i < NUMBER_OF_ANSWERS; i++)
{
if ( (answerChoices,correct,i) == false )
{
cout << "Answer " << i + 1 << " is incorrect.";
}
}
return 0;
}
void PassExam()
{
cout << " You answered " << numCorrect << " questions correctly and "
<< numIncorrect << " questions incorrectly." << endl << endl;
if (numCorrect >= CORRECT_TO_PASS)
{
cout << "Congratulations! You passed the driving exam!" << endl << endl;
}
else
cout << "We're sorry, but you have not passed the driving exam." << endl << endl;
}
void QuestionList()
{
cout << "Please review the questions below so that you are able to pass the exam next time." << endl << endl;
}
void PrintClosing()
{
cout << "This is the end of the DMV Driving Exam. Goodbye!!" << endl;
}