Hi I think im doing fairly good on this program but for some reason its giving me an error on line 27 this program is supposed to compute two statistical values for an array of 500 integers ranging in value from 0 to 2000 what am i doing wrong?

//Driver.cpp

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include "Functions.h"
using namespace std;


int main()
{
	cout<<"\n Functions, arrays, and statistics"
		<<"\n\nThis program will compute two statistical values for an"
		<<"\narray of 500 integers ranging in value from 0 to 2000."; 


	int numbers[499], total = 499;
	double average;

	void FillArray(int numbers[499], int total);
	double AveArray(int numbers[499], int total);

	average = AveArray(numbers[499], total); //error here	
//1 IntelliSense: argument of type "int" is incompatible with parameter of type "int *"	


return 0;
}
//Functions.cpp

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include "Functions.h"
using namespace std;

void FillArray(int numbers[], int total)
{
	srand(123);

	for(int i = 0; i<total; ++i)
	{
		numbers[i] = rand() % 2001;
	}
}

double AveArray(int numbers[], int total)
{
	int sum = 0;
	double average = 0.0;
	
	for (int i = 0; i < 499; ++i)
		sum+=numbers[i];
	
	average = sum/500;

	return average;
}

double StdDeviation(int numbers[], int total, double average)
{
	int sum = 0;
	double finalresult;
	for (int i = 0; i < total; i++)
	{
		sum+=pow((numbers[i]-average),2);
	}
	finalresult=sum/499;

	return finalresult;
}
//functions.h

using namespace std;
void FillArray(int numbers[499], int total);
double AveArray(int numbers[499], int total);
double StdDeviation(int numbers[499], int total, double average);

oh sorry i wasnt clear on the statistical values one is the average of the array
this function calculates the average of the array. it is passed the array, total number(size) and returns the average, either a float or a double.

the other, Standard deviation: this function is passed the array, array size and the average value(what im having trouble with) it calculates and returns the standard deviation.

1)
int anArray[499];

That declares an array of 499 ints with valid indices of 0-498. If you want an array of 500 ints you should declare it like this:

int anArray[500];

2)
In Driver.cpp lines 20 and 21 try to declare functions within main() which is a no no. To call FillArray use this syntax:

int total = 500;
FillArray(numbers, total);

3)
Why bother passing total to AvArray() if you don't use it?

oh i thought if i declared numbers[500] it would give me back an array with valid indices of 0-500, making it in reality 501 integers. thats why i used 499 thinking it would give me an array with valid indices of 0-499 making it in reality 500 integers which is what i need?

Nope.
int anArray[500];
declares an array of 500 ints with valid indices of 0 to 499. You can then pass the name of the array and the "size" of the array to functions that need to use the array.

Beware that "size" is sometimes used to indicate capacity----the maximum amount possible the array could hold and size---the actual number of items in the array. Using descriptors such as MAXNUMBER or actualNumber or index can clarifiy the intent without having to induce it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.