I've had a terrible time with this program. I don't really understand it that much, but have been working on it for about 4 hours so far. One of the problems I'm having is that it keeps saying that local function definitions are illegal. Here's the program so far.


Input:
An integer array of ten numbers: 20,17,9,29,19,9,19,20,20,19
Compile-time array with initialization list of numbers.
NOTE: In main() function

Processing:
Function: computeAverage(const int[], const int):int
countLessThan(const int[], const int, const int):int

Output:
Function: display(const int, const int):void
Display as shown in sample output.

*/

#include <iostream>
using namespace std;

void main(void)
{
    // constants
    const int SIZE = 10;

    // function prototype(s)
    // return by value is used
    int computeAverage(const int[], const int);
    int countLessThan(const int[], const int, const int);
    void display(const int, const int);

    // local data
    int intAverage = 0;
    int count = 0;

    // data declaration(s) & initialization(s)
    // array data: use data from sample output above
    // TODO: declare & initialize array of ten integers
    int numbers[] = {20,17,9,29,19,9,19,20,20,19};

    // start the program
    cout << "*** start of 276Arrays_Ex02.cpp program ***" << endl;
    cout << endl;

    // Compute & return integer average of the array
    // TODO: call computeAverage()function,
    //  which returns average of numbers
    intAverage = computeAverage(numbers, SIZE);

    // Compute & return count of array values less than integer average
    // TODO: call countLessThan() function,
    //  which returns count of numbers less than the average
    count = countLessThan(numbers, intAverage, SIZE);

    // display the required output
    // TODO: call display function,
    //  passing integer average & count of numbers less than average
    display( intAverage, count);

    // terminate the program
    cout << endl;
    cout << endl;
    cout << "*** end of 276Arrays_Ex02.cpp program ***" << endl << endl;
    cin.get();
    return;
}   // end main()

//--------------------------------------------------------------------//
// Function Name: display(const int, const int):void
// Purpose: to display integer average & count less than average
// Values received: integer average, count
// Values returned: <none>
// Notes:
//    display label "Average Integer Score: "
//    display integer average
//    display label "Count of Integers Less Than Average: "
//    display count
//--------------------------------------------------------------------//
// TODO: code the display function
void display(const int num[], const int size)
{

   // display labels and data


// TODO: code the computeAverage function
int computeAverage(int num[], int size)
{
   // local variables (if needed)
	int sum;


   // compute sum
	sum += numbers;

   // compute integer average
	for(int index = 0; index < size; index++)
		 sum += num[index];
		 average = sum / size;

   // return integer average
   return intAverage;
}


// TODO: code the countLessThan function
int countLessThan(const int numbers[],
                  const int intAverage,
                  const int SIZE)
{
   // local variables (if needed)
	int count;

   // count number of values less than average

   // return count
   return count;
}

<< moderator edit: added code tags: [co[u][/u]de][/co[u][/u]de] >>

One of the problems I'm having is that it keeps saying that local function definitions are illegal. Here's the program so far.

Because of bad indenting, you can't see that you've actually got this:

// TODO: code the display function
void display(const int num[], const int size)
{

   // display labels and data


// TODO: code the computeAverage function
   int computeAverage(int num[], int size)
   {

The error message says what is true: you can't define a function within another function.

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.