Question: #include bool grade ( c h a r correctAnswers [ ] , char studentAnswers [ ] ) { int correctCount = 0 ; int incorrectCount

#include
bool grade(char correctAnswers[], char studentAnswers[]){
int correctCount =0;
int incorrectCount =0;
for (inti=0; i<10; i++){
if(correctAnswers[i]== studentAnswers[i]){
correctCount++;
} else {
incorrectCount++;
}
}
if(correctCount8){
std::cout << "Congratulations!" <<std::endl;
std::cout << "You have passed the exam." <<std::endl;
std::cout << "Total number of correct answers: "<< correctCount <<std::endl;
std::cout << "Total number of incorrect answers: "<< incorrectCount <<std::endl;
return true;
} else {
std::cout << "Sorry, you have not passed the exam!" <<std::endl;
std::cout << "Total number of correct answers: "<< correctCount <<std::endl;
std::cout << "Total number of incorrect answers: "<< incorrectCount <<std::endl;
return false;
}
}
int main(){
char correctAnswers[]={'B','D','A','A','C','A','B','A','C','D'};
char studentAnswers[10];
int invalidInputCount =0;
for (inti=0; i<10; i++){
char answer;
do{
std::cout << "Enter answer #"<<i+1<<":
";
std::cin >> answer;
if(answer'A' && answer 'B' && answer 'C' && answer 'D'){
std::cout << "Error! Only A,B,C, and D are valid answers. Please try again." <<std::endl;
invalidInputCount++;
}
if(invalidInputCount>3){
std::cout << "GOODBYE" <<std::endl;
return 0;
}
} while (answer'A' && answer 'B' && answer 'C' && answer 'D');
studentAnswers[i]= answer;
}
grade(correctAnswers, studentAnswers);
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!