Question: C++ question How to compare two int if they are the same? I recieve this error: In function 'int main()': error: invalid types 'int[int]' for

C++ question

How to compare two int if they are the same? I recieve this error:

In function 'int main()': error: invalid types 'int[int]' for array subscript if (target[i] == friends[n].idnum[i]) //compare Ints ^ error: invalid types 'int[int]' for array subscript if (target[i] == friends[n].idnum[i]) //compare Ints

My code:

in.open(input.c_str()); if (!in) cout << "Error opening file." << endl; else { int target; int n2 = 0; in >> target; while (in) { in >> target; n2++; //How many targets for (int i = 0; i < n2; i++) { if (target[i] == friends[n].idnum[i]) //compare Ints { outf << "ID#: " << friends[i].idnum << endl; outf << "Name: " << friends[i].firstname + ',' + friends[i].lastname << endl;; outf << "Test score: " << friends[i].score << endl; outf << "Test responses: " << friends[i].answers << endl; outf << endl; } else { outf << target << "is not a valid student ID# " << endl; } } } in.close(); }

Desired output:

ID#: 56 Name: Larry Black Test score: 95 Test responses: abcdabcdabcdabcdabcbbbbbbbb 13 is not a valid student ID# ID#: 10 Name: Matthew Adams Test score: 15 Test responses: aaaaaaaaaaaa ID#: 19 Name: Jennifer Schwartz Test score: 75 Test responses: aabbcccdabcdabcdabcd -5 is not a valid student ID#

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!