I can't detect the problem to this program that i've made.
there's a problem for sum and average.

#include <iostream>
using namespace std;

float sum(float[], int); // Declaration of function
float average(int, float);// Declaration of function

int main()
{
    int numMonth;
    int count;
    float *sales;
    float userInfo;

    cout << "Please input the number of monthly sales to be input: "<<endl; //Get the array size.
    cin >> numMonth;

    sales = new float[numMonth]; // Allocate the array.

    for (count = 1; count <= numMonth; count++) //Fill the array with values.
    {    
        cout << "Please input the sales for month " << count << endl;
        cin >> userInfo;
        userInfo = sales[count];
    }    

    float sum(float sales[], int numMonth);//Calling function
    cout << "The total sales for the year is $" << sum << endl;

    float average (int numMonth, float sum);// Calling function
    cout << "The average monthly sale is $" << average << endl;

    delete sales;

    system("pause");
    return 0;
}

float sum(float sales[], int numMonth)
{
    float sum;
    float holder=0;
    int count;

    for (count = 0; count <= numMonth; count++)
        holder = holder + sales[count];

    sum = holder; 

    return sum;

}

float average(int numMonth, float sum)
{
     float average;
     average = sum / numMonth;

     return average;
}

One problem is the loop on line 19. The first element of all arrays is numbered 0, not 1. So the loop should be like this:
for (count = 0; count < numMonth; count++) //Fill the array with values.

line 26 does not call a function, it is just declaring a function prototype. Change line 26 like this if you want to call the function

sum(sales, numMonth);//Calling function

Edited 3 Years Ago by Ancient Dragon

This doesn't make much sense.

    cin >> userInfo;
    userInfo = sales[count];

Did you mean this instead?

cin >> userInfo;
sales[count] = userinfo;

Line 26 is a function declaration. What you really want is a function call. It could look something like this:

float temp = sum(sales, numMonth);
cout << temp << endl;

This article has been dead for over six months. Start a new discussion instead.