error in compiling

Jun 26, 2013 at 5:25pm
# include <iostream.h>
int main()
{

int array[7][3];
int i,j;
for (i=0;i<7;i++)
{
for (j=0;j<3;j++)
{
cin>>array[i][j];
}
cout<<endl;
}

for (i=0;i<7;i++)
{
int sum[i];
for (j=0;j<3;j++)
{

cout<<array[i][j]<<" ";
sum[i]=sum[i]+array[i][j];

}
cout<<sum[i];

cout<<endl;
}


return 0;

why this always give constant expression required in function main..by highlighting bold line
Jun 26, 2013 at 5:36pm
Hmmmm...someone correct me if I'm wrong but I think it's because you're declaring sum inside the for-loop. Since i is changing with each iteration of your for-loop it is trying to declare sum over and over with a new size each (based on i) each time.
Topic archived. No new replies allowed.