# Helllppp!!

• 03-21-2011
mrsmoss3791
Helllppp!!
I need some help..here is what i am trying to make and here is the code

One of your professors has asked you to write a program to grade her final exams. which consist of only 20 multiple-choice questions. Each question has one of four possible answers: A, B, C, or D. The file CorrectAnswers.txt, which is on the Student CD, contains the correct answers for all of the questions, each answer is 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-dimensional char array, and then reads the contents of another file, containing a student's answers, into a second charr array. The Student CD has a file named StudentAnswer.txt that you can use for testing purposes. 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. This can be calculated as:

Correctly Answered Questions (divided by) 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 failed the exam.

Code:

```#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; } 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;```

I do not know what is wrong with it!
• 03-21-2011
Mr.777
Don't write return 0 there, instead palce it in the end of main...
• 03-22-2011
Salem
• 03-22-2011
mrsmoss3791
I changed that, but it still will not compile
• 03-22-2011
rogster001
.
Quote:

Originally Posted by mrsmoss3791
I changed that, but it still will not compile

So what are the compiler errors? To save people having to read through it all first...???

none of these arrays are known to the compiler,

Code:

```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++;```
Also its is a headache names and logic wise here:
" if the correct value referenced is not the answer then the wrong answer referenced is not wrong???" or it is wrong no longer as it is false so its is now right, in the wrong array?

And i cannot undserstand why you are trying to use 2d arrays in the way you are, it is redundant here and plain strange the way you are doing it, also this is C++, there are other containers that may be much more suitable for task here, like perhaps std::map, to store the answers at least.
• 03-22-2011
Mr.777
Code:

```#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();       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; return 0; }```
Try this.... It will guaranteed compile...
And if not, post errors generated by your compiler here...
• 03-22-2011
Elysia
The least you could do is change the char arrays to C++ strings.
• 03-22-2011
mrsmoss3791
I changed it to this and now I am getting the same error message four times:

error C2109: subscript requires array or pointer type

Code:

```#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;         int x, answer, correct, wrong, total;     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();       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; return 0; }```
• 03-22-2011
rogster001
int not array
dont just slavishly copy poor code, despite the 'guarantee', as i said earlier you do not have arrays for answer wrong correct, you have simple integers, thus the compiler wants to know why u are trying to use [] with them
• 03-22-2011
Salem