cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
user name:
password:
Forgot your password?
please wait
try again
cancel
forgot your password?
sign up
log in
[Legacy version]
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
error in compiling
error in compiling
Jun 26, 2013 at 5:25pm
Jun 26, 2013 at 5:25pm UTC
ratrangana
(8)
# 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
Jun 26, 2013 at 5:36pm UTC
ENIGMAx
(84)
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.