// Saliha  Babar                CS1A               Chapter 7, Page 446, #9
//
/***************************************************************************
 * GRADE MULTIPLE CHOICE QUESTIONS
 * _________________________________________________________________________
 * This program accepts answers for 20 multiple choice questions, in form of
 * A, B, C, or D. Then it calculates total correct answers, total incorrect 
 * answers as well as incorrect questions list.
 * 
 * There is no specific formula for this program
 * ___________________________________________________________________________
 * INPUT
 *     TOTAL_QUESTIONS      : total question in an exam
 *     userAns              : user answer for questions 
 *     schemeAns            : correct answer for questions (marking scheme)
 * OUTPUT
 *     totalCorrect         : total correct answer entered by user
 * *************************************************************************/
#include <iostream>
using namespace std;


char getUserAns( int QuestionCount );
void compareAnswers ( const char user [], const char scheme[] , int TOTAL_QUESTIONS);

int main() {
	int const TOTAL_QUESTIONS = 20;           // INPUT - total question in exam
	char userAns[TOTAL_QUESTIONS];            // INPUT - user input
	char schemeAns[TOTAL_QUESTIONS] = {'B', 'D', 'A', 'A', 'C',
		                               'A', 'B', 'A', 'C', 'D',
		                               'B', 'C', 'D', 'A', 'D',
		                               'C', 'C', 'B', 'D', 'A'};
	
	// Get the user answer for 20 questions
	for (int i = 0 ; i < 20 ; i++)
	{
		userAns[i] = getUserAns(i);
	}
	
	// Call the void function to make decision
	compareAnswers ( userAns, schemeAns, TOTAL_QUESTIONS );
	
	return 0;
}

char getUserAns( int QuestionCount )
{
	char input;
	cout << "Enter the answer for Question " << (QuestionCount + 1);
	cin >> input;
	
	while ( input != 'A' && input != 'B' && input != 'C' && input != 'D')
	{
		cout << "Only enter letters A,B,C or D. Enter your answer again";
		cin >> input;
	}
	cout << endl;
	
	return input;
}


void compareAnswers ( const char user [], const char scheme[] , int TOTAL_QUESTIONS)
{
	int totalCorrect = 0;              // OUTPUT - total correct answer entered
	
	for ( int i = 0; i < TOTAL_QUESTIONS ; i++)
	{
		if ( user[i] == scheme[i])
		{
			totalCorrect += 1;
		}
		
		else
		{
			cout << "Incorrect Answer for question #" << (i+1) << endl;
		}
	}
	
cout << "Total correct answer(s) is " << totalCorrect << "/20\n";
cout << "Total incorrect answer(s) is " << (TOTAL_QUESTIONS - totalCorrect) << "/20\n";

if ( totalCorrect >= 15)
{
	cout << "Congrats, you passed the test.\n";
}
else
{
	cout << "Sorry, you failed the test.\n";
}
	
}