First-year comp sci student, and first time posting on here.
I have a struct
struct Student{
string name;
int studentID;
int numTests;
int *testScores = new int [TESTS]; //Access with <variableName>.*(testScores + 1), <variableName>.*(testScores + 2), etc.
int avgScore;
};
I’m having trouble trying to figure out how to change the values in the reference array. I guess I can’t figure out the syntax. This is what I’m doing, am I on the right track?
cout << "How many tests did this student take: ";
cin >> numTests;
//iterate numTests amount of times through dynamic array
for (int i = 0; i < numTests; ++i)
{
cout <<"Enter score #" << i + 1 << ": ";
cin >> tempScore;
newStudent.*(testScores + i) = tempScore;
}
I’d appreciate any help in figuring out the right way to go about changing the arrays values.
I’ve tried not using the temp value, changing it to
cin >> newStudent.*(testScores + i);
along with
cin >> *newStudent.(testScores + i);
and a few other variations but I cant seem to find out the correct way to go about it. Still new o the heap.
Noah Stromberg is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1