//Charlotte Davies-Kiernan            CS1A                 Chapter 7 P.446 #
//
/******************************************************************************
 * 
 * Compute Exam Scores
 * ____________________________________________________________________________
 * This program will ask for the 20 correct answers, then ask for the student's
 * 20 answers. It will then display the questions missed, correct vs. student
 * answers, total missed, percentage score, and pass/fail status.
 * 
 * Formulas used:
 * missed = number of questions - correctly answered
 * percent = (correctly answered / number of questions) * 100.0 
 * ____________________________________________________________________________
 * Input
 *   num_questions : Constant representing the total number of questions
 *   correct       : The answer key for the test
 *   student       : The answers the student had put for each question
 * Output
 *   correctCount  : The number of questions answered correctly by the student
 *   missed        : Number of questions the student missed
 *   percent       : Perecntage of correctly answered questions
 *****************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
//Global Variable
const int num_questions = 20;
 
int main() {
//Data Dictionary
	char correct[num_questions]; //INPUT - The answer key for the test
	char student[num_questions]; //INPUT - The answers the student had put for each question
	int correctCount = 0; //OUTPUT - The number of questions answered correctly by the student
	int missed;     //OUTPUT - Number of questions the student missed
	float percent;   //OUTPUT - Perecntage of correctly answered questions
 
//Prompt User
cout << "Enter the correct answers for " << num_questions << " questions: " << endl;
for (int i =0; i < num_questions; i++) {
	cout << "Question " << i + 1 << ": " << endl;
	cin >> correct[i];
	if (correct[i] != 'A' && correct[i] != 'B' && correct[i] != 'C' && correct[i] != 'D'){
		cout << "Invalid Letter please enter A, B, C, or D!" << endl;
		cin >> correct [i];
	}
}
cout << "Enter the student's answers for " << num_questions << " questions: " << endl;
for (int i = 0; i <num_questions; i++) {
	cout << "Question " << i + 1 << ": " << endl;
	cin >> student[i];
	if (student[i] != 'A' && student[i] != 'B' && student[i] != 'C' && student[i] != 'D'){
		cout << "Invalid Letter please enter A, B, C, or D!" << endl;	
		cin >> student[i];
	}
}
//Display Answers
cout << "Questions Missed: " << endl;
cout << "-------------------------------------" << endl;
cout << left << setw(10) << "Question" << setw(15) << "Correct Ans";
cout << setw(15) << "Student Ans" << endl;
cout << "--------------------------------------" << endl;
 
for (int i = 0; i < num_questions; i++) {
	if (student [i] == correct[i]) {
		correctCount++;
	}
	else {
		cout << left << setw(10) << (i + 1) << setw(15) << correct[i];
		cout << setw(15) << student [i] << endl;
	}
}
 
//Calculations
missed = num_questions - correctCount;
percent = ((correctCount * 1.0) / num_questions) * 100.0;
 
//Display Results
cout << "-----------------------------------" << endl;
cout << "Total Questions Missed: " << missed << endl;
cout << fixed << setprecision(2);
cout << "Percentage Correct: " << percent << "%" << endl;
 
if (percent >= 70.0)
	cout << "Result: PASS" << endl;
else
	cout << "Result: FAIL" << endl;
	return 0;
}