Jump to content
  • Advertisement
Sign in to follow this  

C++ function and pointer problem

This topic is 4889 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok i don't know why this isn't working. i pass the address of the array to the function and it displays them rite. I do the same thing but i can get the program to calculate the sum and average. It is a exercise in my book and i can't seem to get it to calcualte with the function. here is my code
void printscores(int numScores , int * rounds);
void calculate(int numScores, int * rounds);

int main(int argc, char* argv[])
{
	int score=0;
	int rounds[10];
	int curRound = 0 ;

	while (curRound < 10 && score > -1 )
	{
		cout << "Enter a score for round " << curRound +1 << " Negative to stop\n";
		cin>> score;
		if (score > 0 )
		{
		rounds[curRound] = score;
		curRound++;
		}
	}
	printscores(curRound , rounds);
	calculate(curRound , rounds);
	cin.get();
	cin.get();
	return 0;
}

void printscores(int numScores,int * rounds)
{
	for ( int i = 0 ; i < numScores ; i++)
	{
		cout << rounds << ", ";
	}

}

THIS IS THE FUNCTION I CAN"T GET IT TO WORK RITE
void calculate(int numScores,int * rounds)
{
	int sum;
	
	for ( int p = 0 ; p < numScores ; p++)
	{
		sum = sum + rounds

; } cout << "\n" << sum; cout << "\n" << sum / numScores; }

i would appreciate it if some1 could help. thnx

Share this post


Link to post
Share on other sites
Advertisement
void calculate(int numScores,int * rounds)
{
int sum = 0;

for ( int p = 0 ; p < numScores ; p++)
{
sum = sum + rounds

;
}
cout << "\n" << sum;
cout << "\n" << sum / numScores;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!