Answer:
The program in C++ is as follows:
#include <iostream>
using namespace std;
int main(){
int questions, answer;
cout<<"Questions: ";
cin>>questions;
int answerkey[questions];
cout<<"Enter answer keys: ";
for(int i = 0; i< questions; i++){
cin>>answerkey[i]; }
int correct = 0;
cout<<"Enter answers: ";
for(int i = 0; i< questions; i++){
cin>>answer;
if(answer == answerkey[i]){
correct++; } }
cout<<"Correct answers: "<<correct<<endl;
cout<<"Percentage correct : "<<(100 * correct)/questions<<"%";
return 0;
}
Explanation:
This declares the number of questions and the answers submitted to each equation
int questions, answer;
Prompt to get the number of questions
cout<<"Questions: ";
This gets input for the number of questions
cin>>questions;
This declares the answerkey as an array
int answerkey[questions];
Prompt to get the answer key
cout<<"Enter answer keys: ";
This iteration gets the answer key for each question
<em> for(int i = 0; i< questions; i++){</em>
<em> cin>>answerkey[i]; }</em>
This initializes the number of correct answers to 0
int correct = 0;
Prompt to get the enter the answers
cout<<"Enter answers: ";
This iterates through the answer keys
for(int i = 0; i< questions; i++){
This gets the answer to each question
cin>>answer;
This compares the answer to the answer key of the question
if(answer == answerkey[i]){
If they are the same, correct is incremented by 1
correct++; } }
Print the number of correct answers
cout<<"Correct answers: "<<correct<<endl;
Print the percentage of correct answers
cout<<"Percentage correct : "<<(100 * correct)/questions<<"%";