Question: C++ XCode I keep getting error while opening file and I do not understand why. Please help. #include #include using namespace std; int num_Of_Matched_Answers( char

C++ XCode

I keep getting error while opening file and I do not understand why. Please help.

#include

#include

using namespace std;

int num_Of_Matched_Answers(char ans[],const char correct_Answers1[], const int n);

void print_Wrong_Answers(char ans[],const char correct_Answers1[], const int n);

int main(){

cout<<"This program reads the answers of the student from a ";

cout<<"file, and shows some results about the quiz. ";

cout<<"Answers are only A, B, C, or D, in uppercase ";

const int n = 20;

char correct_Answers[n];

char ans[n];

int res;

double total_Percentage;

int count;

ifstream reader("correctAnswers.txt");

if(!reader){

cout<<"Error while opening the file. ";

return 0;

}

count = 0;

while( (reader >> correct_Answers[count++]) && count < n );

cout<<"Correct answers were successfully stored. ";

reader.close();

reader.open("studentAnswers.txt");

if(!reader){

cout<<"Error while opening the file. ";

return 0;

}

count = 0;

while( (reader >> ans[count++]) && count < n );

cout<<"Student answers were successfully stored. ";

res = num_Of_Matched_Answers(ans, correct_Answers, n);

total_Percentage = 1.0*res/n;

if(res < 20){

cout<<"The questions that were answered incorrectly ";

print_Wrong_Answers(ans,correct_Answers,n);

}

else{

cout<<"No questions were answered incorrectly. ";

cout<<"-------------------------------------------- ";

}

cout<<"Total missed questions: "<

cout<<"Percentage of correct answers: "<< total_Percentage<

if( total_Percentage >= 0.7 ){

cout<<"Congratulations, you have passed the quiz test. ";

}

else {

cout<<"Sorry, you failed in this . ";

}

cout<<"============================================ ";

return 0;

}

int num_Of_Matched_Answers(char ans[],const char correct_Answers1[], const int size){

int correct = 0;

for(int i=0; i

if( ans[i] == correct_Answers1[i] ){

correct++;

}

}

return correct;

}

// =============================================================

void print_Wrong_Answers(char ans[],const char correct_Answers1[], const int size){

for(int i=0; i

if( ans[i] != correct_Answers1[i] ){

cout<<"Question "<

cout<<"Correct answer: "<

cout<<"Student answer: "<

cout<<"--------------------------------------------"<

}

}

}

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!