1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include <iostream>
#include <cstring>
#include <iomanip>
#include <cmath>
using namespace std;
// This program grades grades an online quiz
// The program ask students to enter multiple-choice
// answers A, B, C, or D, for 10 questions.
// Then compares their answers to the correct
// answers and determines their grade.
int numRight(int given[], int correctAnswers[], int numQuestions);
void inputAnswers(char given[]);
int main()
{
const int size = 10;
char correctAnswers[size] = { 'B', 'C', 'A', 'D', 'B', 'A', 'D', 'C', 'A', 'B' };
int numQuestions[10];
int numRight = 0;
char given[size];
inputAnswers(given);
numRight(given, correctAnswers, numQuestions); //numRight error - expression preceding () of apparent call must have(pointer-to-) function type
{
cout << "Your quiz grade is" << numRight(given, correctAnswers, numQuestions) * 10 << "% \n"; //numRight error, same as line 29
}
return 0;
}
//*******************************
//This function gets the answers*
//*******************************
void inputAnswers(char given[])
{
for (int i = 0; i <= 9; i++)
{
cout << "Please enter your answer for question # " << i + 1 << ": ";
cin >> given[i];
}
return;
}
//********************************************************
//This function finds the number of correct answers given*
//********************************************************
int numRight(int given[], int correctAnswsers[], int numQuestions)
{
char correctAnswers[10] = { 'B', 'C', 'A', 'D', 'B', 'A', 'D', 'C', 'A', 'B' };
int correct = 0;
for (int count = 0; count < numQuestions; count++)
{
if (correctAnswers[count] == given[count])
correct++;
}
return correct;
}
|