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
|
#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;
int A, B, C, D;
const int numQuestions = 10;
void inputAnswers(char given[numQuestions]);
double numRight(char given[numQuestions]);
char given;
int main()
{
char given[10];
inputAnswers(given);
numRight(given);
}
void inputAnswers(char given[])
{
const int numQuestions = 10;
for (int a = 0; a < numQuestions; a++) // "a" must start with 0 as first index of any array is 0 .
{
cout << "Please enter your answer for number #" << a+1 << ": "; // a+1 to print the right num of questions.
cin >> given[a];
}
}
double numRight(char given[])
{
// No need for int A, B, C, D;
double numRight = 0;
char correctAnswers[10] = {'B', 'C', 'A', 'D', 'B', 'A', 'D', 'C', 'A', 'B'};
for (int a = 0; a < numQuestions; a++) // You have to check every element of given array with correctAnswers elements.
{
if (given[a] == correctAnswers[a])
{
numRight++;
}
}
numRight = numRight * 10;
cout << "Your quiz grade is " << numRight << "%" << endl;
return 0;
}
|