This is the question asked, your help is very much appreciated :
One of your professors has asked you to write a program to grade her final exams which consist only of 20 multiple-choice questions. Each question has one of four possible answers:A,B,C or D. The file CorrectAnswers.txt , which I attached has the correct answers for all the questions, each answer written on a separate line. The first line contains the answer to the first question, the second line contains the answer to the second question and so forth.

Write a program that reads the contents of the CorrectAnswers.txt file into a one-demensional char array, and then reads the contents of another file (StudentsAnswers.txt which I have attached)containing the student's answers into a second char array. The program should determine the number of questions that the student missed, and then display the following:
-A list of the questions missed by the student, showing the correct answer and the incorrect answer provided by the student for each missed question.
-The total number of questions missed
-the percentage of questions answered correctly (calculated as correctly answered questions/total number of questions.
-If the percentage of correctly answered questions is 70% or greater, the program should indicate that the student passed the exam. Otherwise, it should indicate that the student has failed the exam.

This is what I have so far , I can't figure out how to calculate the missed questions and and show them with the correct answers and incorrect answers. I also don't know exactly how to read the files correctly. am I supposed to put the files in the source files in my project? I could really use some help thanks.

#include <iostream>
#include <fstream>
using namespace std;

int main ()
{
	const int numOfAnswers= 20;
	const int stringSize=1;
	char correctAnswers[numOfAnswers][stringSize];
	char studentAnswers[numOfAnswers][stringSize]; 
	int totalMissed=0;
	ifstream inputFile;
	
	//Open the file StudentAnswers.
	inputFile.open("CorrectAnswers.txt");

	//Read the 20 answers from the file CorrectAnswers into the char array correctAnswers.
	for (int count=0; count < numOfAnswers; count++)
	{
		inputFile>> correctAnswers[count][stringSize];

	}
	
	//close the file.
	inputFile.close();
	
	//Open the file StudentAnswers.
	inputFile.open("StudentAnswers.txt");

	//Read the 20 answers from the file StudentAnswers into the char array studentAnswers.
	for (int count=0; count < numOfAnswers; count++)
	{
		inputFile>> studentAnswers[count][stringSize];
	}

	//close the file.
	inputFile.close();
	
	return 0;
}

Well the way I would do it is use a for loop to compare the two arrays and a bool array to track what answers are wrong.

for(x = 0; x <  20; x++)
       if(correct[x] != answer[x])
             wrong[x]=false;

for(x = 0; x < 20; x++) {
       if(!wrong[x]) {
          cout<<x<<". wrong"<<endl;
          total++;
}
       else
          cout<<x<<". right"<<endl;
}

cout<<total<<"wrong, "<<(20-total)<<"right"<<endl;

Don't forget to initialise the bool array to true, and you can figure out how to do the percentages by your self quite easily. As for fstream, this link is pretty helpful http://www.cplusplus.com/doc/tutorial/files.html

thanks I'll try to do that right now :)

I read the website instructions. However, I don't understand where my file is supposed to be located. Do I put it in the source folder?

Whenever I used .txt files they were just on the desktop, but I'd put them in the source folder to be sure. Sorry but I'm not all that experienced.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.