Invalid types 'double [100][double]' for a

2019-03-04 05:11发布

#define MAX 100 
double velocity[MAX];
for (itr = 0; itr < velocity[0]; itr = itr + 1)
    {
        velocity[itr] = velocity[0] - (1*itr);
        distance[itr] = rk4_solve(itr, velocity);
        cout << setw(5) << itr << setw(9) << velocity[itr] << setprecision(4) << setw(10) << distance[itr] << endl;
    }

I am trying to input values into the array but for some reason I get the error: i Invalid types 'double [100][double]' for array subscript for the 3 lines inside the for loop.

3条回答
祖国的老花朵
2楼-- · 2019-03-04 05:46

itr must be an int (or other integer type)

Be aware that you are comparing itr with velocity[0] in the for cycle (itr < velocity[0];). You probably meant itr < MAX, and I hope somewhere you defined the variable itr

查看更多
爷、活的狠高调
3楼-- · 2019-03-04 06:05

Just had a similar issue.

Array index's cannot be double or float.

I fixed my issue by typecasting the index's to int.

查看更多
Viruses.
4楼-- · 2019-03-04 06:09

A total shot in the dark, but could you be missing a semicolon just above the lines shown?

查看更多
登录 后发表回答