Passing an array to the function?

I'm writing a code for the problem below and I have an issue with the function header, prototypes, and call in the main.
I'm not sure how to pass an array to the function!


and this is my code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//

void average (double [], int);    

	}
	average(scores,numScores );    
	
}


void average (double scores, int numScores)    //<<===============================================================
{
	int total =0;
	for (int count =0 ; count< numScores; count ++)
	{
		total += scores [numScores];
	}

	int avg = total/ numScores;
	cout << " The average of the scores is : " << avg << endl;
}



Thanks in advance!
Last edited on
You ahve brackets here
void average (double [], int);

But not here
void average (double scores, int numScores)
Ok thanks, that's fix now. But I don't get the right total, I think I'm doing something wrong in the for loop in the function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14


void average(double scores[], int numScores)    
{
	double total = 0;

	for (int count = 0; count< numScores; count++)
	{
		total += (*scores);
	}
	cout << "total is" << total << endl;
	double avg = total / numScores;
	cout << " The average of the scores is : " << avg << endl;
}


Thank you!
Last edited on
You are adding first value repeadtly. Why did you change your loop? It was fine.
It was giving me a wrong answer
How can I fix that?
Loop itself was perfectly fine. You just tried to fit double variable into int.
Okay I got it! Thank you so much
Topic archived. No new replies allowed.