I am writing a program that will compare stings of data (true false answers) against an answer key which is another string.

for example, the data for the students answers looks like this.

tfttftttf

so question 1 is true question 2 is false etc.

Here is the code I have come up with to compare the "answerkey" to the students answers.

void scoreanswers(scores studentanswers[50], string &answerkey, int &count)
{
	for (int i=0;i<count;i++)
	{
		for (int j=0;j<22;j++)
		{
			if (answerkey.substr[j]==studentanswers[count].answers[j])
				studentanswers[count].grade+=5;
			else
				if (answerkey.substr[j]!=studentanswers[count].answers[j])
					studentanswers[count].grade=-2;
		}//end for
	}//end for
}//end scoreanswers

the problem is I get this error. Can anyone help me decipher this error

1>g:\c++\scoretest\scoretest\scoretest.cpp(120) : error C3867: 'std::basic_string<_Elem,_Traits,_Ax>::substr': function call missing argument list; use '&std::basic_string<_Elem,_Traits,_Ax>::substr' to create a pointer to member
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1>g:\c++\scoretest\scoretest\scoretest.cpp(120) : error C2109: subscript requires array or pointer type

its not substr, its substr(i);

Plus you are making this way to complicated.

But before I suggest something, Are these assumptions correct :

1) You are comparing the student answer keys with the correct ones.
2) The student has answered all the question.
3) You need to count how many correct the student has.
4) Any more?

its not substr, its substr(i);

Plus you are making this way to complicated.

But before I suggest something, Are these assumptions correct :

1) You are comparing the student answer keys with the correct ones.
2) The student has answered all the question.
3) You need to count how many correct the student has.
4) Any more?

1) yes I am comparing the students answers to a single answerkey
2) no there is the possibility that one or more answers is left blank
3) yes need to count correct answers and multiply by 5 and deduct 2 for every incorrect answer.

I had planned to run the students answers through another loop to find spaces (skipped answers) and then multiply those out accordingly.

What you need to do is read character by character.

First check if the student answer key is the same size as the actual
correct answer key. Subtract 2 points for every length difference.
so :

unsigned int differ =  answerKey.size() - studentAnswer[i].size();
if( diff )  studentAnswer[i].grade -= diff * 2

Now you need to compare each answer, character by character.

So use a for loop starting from 0 to the number of students.
Have the sizeDiff check from above, inside the for loop. Now create another nested for loop to check the answer character by character

So your loop could look like this :

for currStudents = 0 to MaxNumOfstudents; currStudents++)
{
    sizeDifference  =  answerKey.size() - studentanswer[currStudent].answer.size();
if( sizeDifference > 0  ) //subtract grade

for key = 0 to key < answerKey.size(); ++key)
{
  if currentStudents answer key is != currentAnswerKey 
         then subtract 2 points
  else add 5 points
 }
}
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.