help i'm rather new at this but have some understanding but am having some probs with

1>c:\users\kysinden\documents\visual studio 2008\projects\real\real\test.cpp(8) : error C2144: syntax error : 'int' should be preceded by ';'
1>c:\users\kysinden\documents\visual studio 2008\projects\real\real\test.cpp(9) : error C2447: '{' : missing function header (old-style formal list?)

i am makeing an number averageing script with a variable amount of numbers to be averaged.

Here is my code

#include <set>
#include <iostream>

using namespace std;
     double atotal()

int main();
{
    double itotal = 0;
    double dnumber1 = 0.0;
    double dnumber2 = 0.0;
    double dnumber3 = 0.0;
    double daverage = 0.0;
    double a = 0;

    cout << "please enter how many numbers: " <<endl;
    cin >> itotal;
    atotal(itotal);
    cout << "start entering numbers" <<endl;
    for(a = 0; a < itotal; ++a);
    {
        cin >> atotal(a);
    }
    //cin >> dnumber1;
    //cin >> dnumber2;
    //cin >> dnumber3;

    daverage = (dnumber1 + dnumber2 + dnumber3) / 3;

    cout << "the average for your numbers is : " << daverage << endl <<endl;

    system ("pause");
    return 0;
}

thx for ur help.

Hello,

First of all..

int main();

Shouldn't have a semicolon, therefore it should just be:

int main()
{

   return 0;
}

You've also declared a function, but, it doesnn't mean it's wrong, you can set the prototype (Especially if your using the function in main, but it's actual functiuanlity is set outside of main).

Also, you seem to be accepting numbers (in a for loop) that only get entered into a single variable.. This isn't right, you need to create an array for the numbers to be stored in, and then pass this array to a function that calculates all of the numbers together. (I think this is how you want the program to work!)

Have a look at this example:

#include <set>
#include <iostream>

using namespace std;

     double atotal(double *theNumbers, int theTotal)
     {
        int total = 0;

        for(int i=0; (i < theTotal); i++)
        {
            total += theNumbers[i];

        }
        return total;
     }

    double daverage(double *theNumbers, int theTotal)
    {
        int total = atotal(theNumbers, theTotal)/theTotal;

        return total;

    }

int main()
{
    int itotal = 0;

    cout << "please enter how many numbers: " <<endl;
    cin >> itotal;
    double* a = new double[itotal];

    cout << "start entering numbers" <<endl;
    for(int i = 0; (i < itotal); i++)
    {
        cin >> a[i];
    }
    // This will display the numbers added together
    cout << "The total sum of the numbers is: " << atotal(a, itotal) << endl;
    cout << "The average of the numbers is: " << daverage(a, itotal) << endl;

    system ("pause");
    return 0;
}

It should give you an insight in how the program should be developed.

Hope this clears atleast a few things up :)

Edited 4 Years Ago by phorce: Better example

Please can you close the thread, mark is as solved and give reputation respectively. If the problem has been solved! :)

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