so im calculating the avergae of 5 numbers ive put in the array but when i compile i get a very large number
heres my code

#include <iostream>
using namespace std;

int calcAverage()
{
int sum=0;
int average;
int TESTVALS[5] = {2, 18, 1, 27, 16};
for(int i = 1; i < 5; i++)
sum+= TESTVALS[i];
average= sum/5;
cout<<"average";
}

int main()
{
  cout << "The average value" << calcAverage() << endl;
  system("pause");
  return 0;
}

and yes i need the calcAverage as a prototype. i can do it w.o the protoype but i am going to need it later on

You forgot to add return average to your function--

int calcAverage()
{
int sum=0;
int average;
int TESTVALS[5] = {2, 18, 1, 27, 16};
for(int i = 1; i < 5; i++)
sum+= TESTVALS[i];
average= sum/5;
return average;
}

-- so its possible that due to the lack of the return statement the function was assigned some space of an int that wasn't initialized.

This question has already been answered. Start a new discussion instead.