error: invalid types 'double [199][double]' for array subscript|

Oct 20, 2011 at 1:19am
I am doing a school project I keep getting this error for my array operations starting at line 35:

#include <iostream>
#include <iomanip>
#include <cmath>
#include <valarray>
#include <cstdio>
#include <cstdlib>

double const pi=4*atan(1);
using namespace std;

int main()
{
double dia, diaf, K, mu, eps, dD, dx, ang, n, D;
double ds[199];
double Y[199];
double p[199];
double x[199];
double S[199];
ang= 12*pi/180;
x[0]=3;
S[0]=4;
cout <<"hello" << endl;
ds[0]=x[0]*S[1];
cout << ds[1];
cout << "goodbye";
Y[0]=300+320*eps;
p[0]=Y[1];
dia= 0.001;
diaf= 0.0006;
D=dia;
mu= 0.2;
dD=(dia-diaf)/200;
dx=dD/(2*tan(ang));
for(n=0; n<199; n++){
dS[n]=2*(dD/D)*(Y[n]*(1+mu/tan(ang)-S[n]*mu/tan(ang)));
S[n+1]=S[n]+dS[n];
D=D-dD;
eps=2*log(dia/diaf);
Y[n+1]=Y[n]+K*eps;
p[n+1]=Y[n+1]-S[n+1];
x[n+1]=x[n]+dx;
}
return 0;
}

thank you for your help
Oct 20, 2011 at 1:54am
You can't use double to index an array. For example:
1
2
3
4
5
6
double n=1
double array[10]
//wrong:
array[n]=1;
//right:
array[(size_t)n]=1;
Topic archived. No new replies allowed.