arrays & void functions, reading from a file, error msg

I cannot figure out what this error message means:
invalid types 'double[double]' for array subscript.
I've gotten this and similar ones as I've tried to correct it.
I also realize there may be other errors in my program, but this is one I have no clue about and it's preventing me from getting further because the program won't compile.
Here's my code:

using namespace std;
#include<fstream>
#include<iostream>
#include<cmath>
#include<iomanip>
void fueleco(double[], int);
int main()
{
double speed[9], max, i=0, n, s;
int numval=1;
ifstream datain("pa2data.txt");
cout<<" SPEED "" FUEL "" EMISSIONS "" RATIO "<<endl;
cout<<" MPH "" MPG "" GMS CO/KM "" MPG/(GM/KM)"<<endl;
datain>>speed[0];
while (!datain.fail())
{
datain>>speed[i];
i++;
numval++;
}
fueleco(speed, numval);

system("pause");
return 0;
}

void fueleco(double speed[], int numval)
{

double mpg, emissions, ratio, i;

mpg[i]=3*speed[i]-0.03*pow(speed[i],2);
emissions[i]=1.5+0.01*speed[i];
ratio[i]=mpg[i]/emissions[i];
cout<<setprecision(2)<<setw(13)<<speed[i];
cout<<setprecision(2)<<setw(14)<<mpg[i];
cout<<setprecision(2)<<setw(19)<<emissions[i];
cout<<setprecision(2)<<setw(15)<<ratio[i]<<endl;
cout<<"The maximum ratio of mpg/emissions = "<<max<<endl;
cout<<"At a speed of "<<ratio<<" mpg "<<endl;

}
First, when you post code, please use tags, as described here: http://www.cplusplus.com/articles/firedraco1/
It makes the code much easier to read and it shows line numbers.

Now concerning your program, there are several problems in function fueleco():

- mpg is a normal variable and you try to use it as an array (like mpg[i]), which will be reported as an error by the compiler.

- In the same function, you are using i as an array index, but i is not an integer (which does not make much sense).

- Still in fueleco(), i is used without being initialized, i.e. you did not give a value to i before using it somewhere else. This means that i can have any (random) value, which is not what you want.
Topic archived. No new replies allowed.