Errors need help

I need help! I keep getting this error in line 46
initialization with {..} expected for agrregate object
and error c2440 cannot convert from bool to double []

any tips? Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  #include<iostream>
#include<fstream>
#include<string>
using namespace std;
void getgrad (double[], ifstream &, float &);
double readarr (double[], ifstream &);
int main()
{
	ifstream inFile;
	ofstream outFile;
	string StudentID;
	double answer[20];
	float Answers;

	inFile.open("Answers.txt");
	outFile.open("StudentsAnswersAndID.txt");

	readarr(answer, inFile);

	while (!inFile.eof())
	{
	
		inFile >> StudentID;
		getgrad(answer, inFile, Answers);

	}

	outFile << StudentID << Answers;

	return 0;
}

double readarr(double A[], ifstream & b)
{
	int i;
	for (i = 0; i <= 20; i++)
	{
		b >> A[i];
	}
	return A[i];
}

void getgrad(double B[], ifstream & c, float & grade)
{
	bool found = true;
	if (double B[] = true)
	{
		grade += 5;

	}



}
Last edited on
3 huge issues

1) if (double b[] = true)

This is making a new variable of type double, and initializes it to true

what you want is:

if (b[] == true)

idk what the logic of that function is, but i don't think you can just compare a whole array as B[], an index needs to be given
'B[]' is an array of doubles. What are you trying to do with it? You can't convert from an array of doubles to a boolean value.
^ also what he mentioned
Ok so i somehow fixed the error but i cant get the code to output correctly.. Let me explain what im doing first. I need to compare the student answers to the answer key and see how many of them they got right. For each question they got right, they get five points. The hard part is how do i compare the answerkey to the students answers. The answer key is in the first line of the file and the next line followed by the students ID and their answers for the 20 questions. After that i have to output the results to a output file which i know how to do and their scores.
Last edited on
here is the logic:

you have to open the file which contains the answer key
then create an array where index [0] represents question 1, index[1] represents question 2, etc..
im assuming your text file is in this format:
50
20
40
30
?? where 50 is the right answer for question 1, 20 for question 2 and so on?

If it is like this, then you just have to read in the first value, put it in the first index, read in the second value, put it in the second index...

when you're done, make another for loop which iterates through student[] and answer[] and compare each index to see if they match

student[0] == answer[0]
they got it right!!
else
wrong

does this make sense?
Topic archived. No new replies allowed.