// Andres Guzman CSC5 Chapter 7, P. 446, #9
/******************************************************************************
*
* COMPARE STUDENT ANSWERS
* ____________________________________________________________________________
* This program will determine whether a students answers match the correct
* answer sheet.
* ____________________________________________________________________________
*
* INPUT
*
* [SIZE] = array size
* coranswers[SIZE] = correct answers list
* studanswers[SIZE] = student answers
* OUTPUT
*
* correct = subscripts that match correct list
* incorrect = subscripts that dont match correct list
*
******************************************************************************/
#include <iostream>
using namespace std;
int main()
{
const int SIZE = 20; //Array Size
int i; //counter to cycle subscripts
//Initialization list of correct answers
char coranswers[SIZE] = {'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D', 'B',
'C', 'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A'};
char studanswers[SIZE]; //Subscripts for characters
int correct = 0; //Accumulator for correct answers
int incorrect = 0; //Accumulator for incorrect answers
//
//Initializing For Loop
for(i = 0; i < SIZE; i++)
{
cout << "Question " << (i + 1) << " Student Answer: ";
cin >> studanswers[i];
while(studanswers[i] != 'A' && studanswers[i] != 'B' &&
studanswers[i] != 'C' && studanswers[i] != 'D') //Input Validation
{
cout << "Invalid Letter Grade." << endl;
cout << "Question " << (i + 1) << " Student Answer: ";
cin >> studanswers[i];
}
if(studanswers[i] == coranswers[i]) //Determines if answers match
{
correct++; //Increases amount of correct answers
}
else
{
incorrect++; //Increases amount of incorrect answers
}
cout << endl;
}
if(correct >= 15) //Determines if there are 15 or more correct answers
{
cout << "\nPASS!\n" << "Correct Questions: " << correct << endl;
cout << "Incorrect Questions: " << incorrect;
}
else //When there are less than 15 correct answers
{
cout << "\nFail\n" << "Correct Questions: " << correct << endl;
cout << "Incorrect Questions: " << incorrect;
}
cout << "\n\nIncorrect Questions" << endl;
//
//Initializing For Loop for display all the incorrect answers
for(i = 0; i < SIZE; i++)
{
if(studanswers[i] != coranswers[i]) //When the answers do not match
cout << "Question " << (i + 1) << endl;
}
return 0;
}