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 ;
}

Recommended Answers

All 7 Replies

in line 19, you have a semicolon. That should do it

in line 19, you have a semicolon. That should do it

still not done :(

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.

commented: Good :) +8

Besides, you can't declare two variables with the same name... see: int num[] and int num

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".

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

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.