-
arrays - simple problem
Hello,
I wrote this simple piece of code.
Code:
int
main(void)
int score [100];
score [0] = 5;
score [1] = 3;
for (i=2; 1<=100; i=i+1)
score(i) = score[i-1] + score[i-2];
return(0);
When trying to compile it, i get this error:
Code:
flash:~>gcc formula.c -o form
formula.c: In function `main':
formula.c:8: error: syntax error before "score"
flash:~>pico +8 formula.c
I don't really understand what's wrong with line 8. To me, everything looks fine.
Any ideas. Thanks
-
change this
score(i) = score[i-1] + score[i-2];
to this
score[i] = score[i-1] + score[i-2];
and it should compile. its gonna spit out some nasty values
though because your loop runs through the entire array but only
two elements are initiallised
EDIT:
for (i=2; 1<=100; i=i+1)
should probably be changed to
for (i=2; i<=100; i=i+1)
-
Don't forget to box in your main.
Code:
int
main(void)
{
int score [100];
score [0] = 5;
score [1] = 3;
for (i=2; 1<=100; i=i+1)
score(i) = score[i-1] + score[i-2];
return(0);
}