Please help! Character Array problem

Hi, I'm very new to c++, first semester. I'm having a great deal of trouble with this program I'm suppose to write. Ultimately its supposed to grade a students test with a teachers test. So one array will be the teacher's answers(which is pre-assigned, the book gives the teachers answers), and the second array will be the student's answers which the teacher must type in. What I'm having trouble with is making it so the program recognizes when a letter other than A-D is typed.

I tried a while loop, but a weird error comes up,

operand types are incompatible ( "char*" and "char")

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


void Exam_Intro();




int main()
{
const int Teachers_Array= 20; //Array Size
const int Student_Array=20; // Array Size

char Teachers_Exam[Teachers_Array] = {'B','D','A','A','C','A','B','A','C','D',
'B','C','D','A','D','C','C','B','D','A'}; // Holds Teachers Answers
char Student_Exam[Student_Array];


// Introduction and Explanation to the program for the user.
Exam_Intro();

// Answers of Student.
cout<< "Please type in the answers of your student:"<<endl;

for (int count=0; count<Teachers_Array; count++)
{
cout<<"Question #"<<(count+1)<< ". ";
cin>>(Student_Exam [count]);
while( Student_Exam != 'A' && Student_Exam != 'B' && Student_Exam != 'C' && Student_Exam != 'D')
{
cout<< "Please enter only letters A, B, C, or D."<<endl;
}
for ( int x=0; x< Student_Array; x++)
{
Student_Exam[x]= toupper( 'A');
Student_Exam[x]= toupper( 'B');
Student_Exam[x]= toupper( 'C');
Student_Exam[x]= toupper( 'D');

}
}
Firstly. After cin >> Student_Exam[count]; make sure to use cin.ignore(); /* look it up */.

Next.
1
2
3
4
5
6
for ( int x=0; x< Student_Array; x++) {
Student_Exam[x]= toupper( 'A');
Student_Exam[x]= toupper( 'B');
Student_Exam[x]= toupper( 'C');
Student_Exam[x]= toupper( 'D');
}

This code is broken. It will change every Student exam answer to A, then B, then C, then D. After this loop is done every student answer will be D.

Re-think your logic. And step by step write in comments in English describing what should happen. Once you have the logic sorted then you write the code under each comment :)

e.g
1
2
3
4
5
6
7
8
9
10
11
12
int main() {
// Declare variables/arrays

// Print information

// loop getting answers for student

// loop turning all answers to uppercase

// loop doing a check against teach and calculating score

}

Last edited on
Ok thank you , I know what you mean. This is a different type of thinking I need to develop. I'll work on it more and come back.

I was also wondering why my while loop doesn't work and what the error means?
operand types are incompatible ( "char*" and "char")


Thank you Zaita
Last edited on
Topic archived. No new replies allowed.