Thread: what is an Illegal floating point ?

1. what is an Illegal floating point ?

Hi all, i made an array and there is just one error left to fix and i really dont understand it the problem is in these lines:

Code:
```Average+=scores[i];
Average=Average/N;
printf("\n Average score = %f",Average);

for(j=0;j<M;j++)

Average+=scores[j];
Average=Average/M;
printf("\n Average = %f",Average);```
the error the compiler gives me is "Illegal use of Floating Point" , can anyone help me please ?

2. How about showing the types of the variables...?

I'm guessing you used a floating point for an array index but I'm not really that knowledgeable on floating point operations.

3. ok here is the whole code :

Code:
```#include <stdio.h>
#include <math.h>
#include <conio.h>
#define max_student 50
#define max_subject 7
main()

{
int scores[max_student][max_subject];
int N,M;
int i,j;

do
{
printf("\n Enter No. Of students");
scanf("%d",&N);
}
while(N<1||N>max_student);

do
{
printf("\n Enter No. Of Subjects");
scanf("%d",&M);
}
while(M<1 || M>max_subject);

for(i=0;i<=N;i++)

{
printf("\n enter scores of student No. %d",i+1);
scanf("%d",&scores[i]);
}

for(j=0;j<=M;j++)

{
printf("\n Enter score of subject No. %d",j+1);
scanf("%d",&scores[j]);
}

double Average=0.0;

for(i=0;i<N;i++)

Average+=scores[i];
Average=Average/N;
printf("\n Average score = %f",Average);

for(j=0;j<M;j++)

Average+=scores[j];
Average=Average/M;
printf("\n Average = %f",Average);

getch();
}```

4. It's all there in the errors:
Code:
```1>------ Build started: Project: CProg4, Configuration: Debug Win32 ------
1>Compiling...
1>CProg4.cpp
1>cprog4.cpp(43) : error C2297: '+=' : illegal, right operand has type 'int [7]'
1>cprog4.cpp(43) : error C2440: '+=' : cannot convert from 'int [7]' to 'double'
1>cprog4.cpp(48) : error C2297: '+=' : illegal, right operand has type 'int [7]'
1>cprog4.cpp(48) : error C2440: '+=' : cannot convert from 'int [7]' to 'double'
1>Build log was saved at "????"
1>CProg4 - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========```
Specifically it points to these lines:
Code:
```int scores[max_student][max_subject];

...

for(i=0;i<N;i++)
Average+=scores[i];

...

for(j=0;j<M;j++)
Average+=scores[j];```
Based on what "scores" is it should be obvious.

5. still having same problem after making it like this :

Code:
```double scores[max_student][max_subject];
double N,M;
double i,j;```
and i also tried to initialize i=0.0 instead of just 0 ,j=0.0 instead of 0

6. The problem isn't that "scores" is two-dimensional array of ints, it's that it's a two-dimensional array. "scores[i]" is a one dimensional array. You can't add an array of objects, no matter the type (int/float/double), to a variable like you are trying to do. You probably want a double/nested loop.

7. If your really having trouble with something take the time to isolate and experiment with the suspects:
Code:
```#include <stdio.h>

int main(void)
{
int scores[2][2] = { {1, 2}, {3, 4} };

/* scanf("%d", &scores[0]);   warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int (*)[2]’ */
scanf("%d", &scores[0][0]);  /* ok */

/* scores[0] += 1;           error: invalid operands to binary + */
scores[0][0] += 1;          /* ok */

printf("scores[0][0] += 1 = %d \n", scores[0][0] );

return 0;
}```