Why I can't get this program complied ? I am geting " 20 expected unqualified-id before '{' token "

#include <iostream>
using namespace std ;
int answer(int num[] ,int num );
main ()
{
     int ary[10] ;
    
     cout << " Please Enter 10 integer values" << endl ;
     
     for ( int i = 0 ; i <= 9 ; i++ )
     {  
         cout << " Enter the value of  " << i + 1 << " array element : " ;
         cin >> ary[i] ;
     int total = answer ( ary,i );
     
     }
}
     
int answer (int num[] ,int num );
{
    int sum = 0 ;
    for ( int i = 0 ; i < 10 ; i ++ )
    {
        sum+ = num [i] ;
    }
        return sum ;
}

1. main() is a function, you must specify a return type. The ISO standard requires that the type be int.

2. Both of your parameters in answer() are called "num" change the name of one of them.

3. Line 24, you are trying to use the operator "+=", you can't split it like that. Get rid of the extra space.

Edited 6 Years Ago by Fbody: n/a

Comments
Good :)

1. main() is a function, you must specify a return type. The ISO standard requires that the type be int.

2. Both of your parameters in answer() are called "num" change the name of one of them.

3. Line 24, you are trying to use the operator "+=", you can't split it like that. Get rid of the extra space.

I have made above mention correction ,thanks for your fast reply but I am still getting following errors.

In function `int answer(int*, int)':

24 invalid types `int[int]' for array subscript

#include <iostream>
using namespace std ;
int answer(int num[] ,int ara );
int main ()
{
     int ary[10] ;
    
     cout << " Please Enter 10 integer values" << endl ;
     
     for ( int i = 0 ; i <= 9 ; i++ )
     {  
         cout << " Enter the value of  " << i + 1 << " array element : " ;
         cin >> ary[i] ;
     int total = answer ( ary,i );
     
     }
}
     
int answer ( int num[] ,int ara )
{
    int sum = 0 ;
    for ( int i = 0 ; i < 10 ; i ++ )
    {
        sum+= ara[i] ;
    }
        return sum ;
}

You need to keep better track of your variable names; "ara" is not the name of your array. The proper name is "num".

Edited 6 Years Ago by Fbody: n/a

You need to keep better track of your variable names; "ara" is not the name of your array. The proper name is "num".

thanks for your help ,problem resolved

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