Issue passing array to function

I have an array of test scores that I want to pass to a function and I think I have done that part fine but now im having an issue using the array in the function. The error I am getting is: "double *scores expression must have class type"

The line I am using to send the array to the function is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//create an array
	double *scores = new double [numScores];
	//create a for loop to fill the array
	for ( int i = 0; i < numScores; i++){
			//ask the user to enter a score
		cout << "\n Please enter a score: ";
		//assing the score to the array
		cin >> scores[i];	
	}

	//call the function to determine what grades pass/fail
	if (scoreMark(scores,passGrade)){


	}



And here is where I am having an issue the problem is the *scores in the start of the for loop:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
		for ( int i =0; i < *scores.size(); i++){
				//check if score is equal to or less then a pass
			if (scores[i] >= pass){
				//if in here score is a pass show it on the screen
				cout << "\n score " << i << " is " <<scores[i] << " and is a ";
				//finish the sentence
				cout << "pass!";

			}else{
				//if in here score is a fail show it on the screen
				cout << "\n score " << i << " is " <<scores[i] << " and is a fail.";

			}
				

		}

		return true;

}



Im hoping someone can explain this error more to me and maybe explaining the * before the scores variable that is not my idea and I dont really understand that quite yet either.
scores.size() is not a valid expression. If scores were a vector it might be valid, but otherwise no. Scores is just an array, and it doesn't "know" its own size. Try using this instead: for (int i = 0;i < numScores;i ++) {
As for the *, it has to do with pointers. Look up pointers and read about them a lot if you want to be able to understand what the * does in that context. e: Actually, I misread. You will probably need to pass the size of the array to the function as well, and then use that passed variable in the for loop. i.e. make it so that the way scoreMark is called is scoreMark(array,sizeofarray,passGrade) and then use the passed value to limit the for loop.
Last edited on
Topic archived. No new replies allowed.