0

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 ;
}
3
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by naseerhaider
3

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 by Fbody: n/a

Votes + Comments
Good :)
0

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

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

Edited by Fbody: n/a

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.