18 E:\hw6aKJJ.cpp uninitialized const `array'

//program will take a user inputed list of integer numbers and use three
//function calls in order to find the largest, smallest, and average values

#include <iostream>
#include <cstring>
using namespace std;

//function prototypes
int largest(int array[]); //largest function
int smallest(int array[]); //smallest function
double average(const int* array[], int length); //average function

int main(void)
const int MAX = 100;
const int array[MAX]; //array to test
int length, i=0, large, small; //number of ints in array
int aver;
//get test values

cout << "Please enter the number of integers in your series-->> ";
cin >> length;

cout << "Please enter the series of integers to test -->> " << endl;
cin >> array[i];

aver = average(array[i]);

cout << "The average value in the series is -->> " << aver;

return 0;

double average(const int array[], int length)
int total, i;
double ave;

for(i = 0; i < length; i++)
cin >> array[i]; //read into array here

//calculate values
for(i = 0; i < length; i++)
total += array[i]; //sum
} //end for loop
ave = total / length;

return ave;

I can't figure out why I am getting this error.
The error tells you word for word what is wrong. You're declaring a const array like this:
const int array[MAX]; //array to test
You didn't initialize the array to hold anything like this:
const int array[MAX] = {1, 2, 3, 4}; //array to test but you did declare it const. But saying const means you can't change it later. If the compiler let you go, it would essentially let you declare an array that can never be updated to have anything in it. I don't think you want that const in the array declaration.
Last edited on
Topic archived. No new replies allowed.