help with output files

Hey so I have to output a bunch of data to a blank document and I can't figure out how to do it. I think it has something to do with my parameters of my function. Here is the error message:
Rocket3.C: In function â:
Rocket3.C:26:21: error: invalid operands of types â and â to binary â
Rocket3.C:35:20: error: invalid operands of types â and â to binary â
Rocket3.C: In function â:
Rocket3.C:71:16: error: invalid operands of types â and â to binary â
Rocket3.C:88:46: error: invalid initialization of non-const reference of type â from an rvalue of type â
Rocket3.C:9:6: error: in passing argument 7 of â
Rocket3.C:89:16: error: invalid operands of types â and â to binary â
Rocket3.C:90:16: error: invalid operands of types â and â to binary â
Rocket3.C:91:16: error: invalid operands of types â and â to binary â
Rocket3.C:92:16: error: invalid operands of types â and â to binary â
[1] + Done gedit

And here is the code:
#include <iostream> //
#include <fstream>
#include <cstdlib>
#include <cmath>
using namespace std; //allows access to cin and cout
void heightwithT(double dt, double b, double A, double mo, double mf, double* T1, std::ofstream &filename2)
{

double t;
double g = -9.8;
double h = 0;
double v = 0;
double mi;
double p = 1.225;
double k = -.5*p*A;
double Ti;
for(t = 0; t <= 1; t += dt)
{
Ti = b*t*(1-t);
mi = mo + (mf -mo)*(3*pow(t,2) - 2*pow(t,3));
v = v + dt*(g + k*pow(v, 2)/mi + (Ti/mi));
h = h + dt*v;
&filename2 << t << " " << v << " " << h << endl;
}
T1[0] = h;
T1[1] = v;
while(v >= 0)
{
v = v + dt*(g + k*pow(v, 2)/mf);
h = h + v*dt;
t = t + dt;
&filename2 << t << " " << v << " " << h << endl;
}
T1[2] = h;
T1[3] = t;
return;

}


int main()
{
const int SIZE = 60;
char filename[SIZE];
char filename2[SIZE];
ifstream file;
ofstream file2;
while(true)
{
cout << "Enter the name of file with data:\n" << "dt(s), b(N/s^2), A(m^2), mi(kg), mf(kg). \n";
cin.getline(filename, SIZE);
file.open(filename); // associate inFile with a file
if (!file.is_open()) // failed to open file
{
cout << "You typed the wrong file name \n" << filename << " can't be opened. Figure it out dude \n";
cout << "Peace out \n";
exit(EXIT_FAILURE);
}
cout << "Enter the name of blank output file";
cin.getline(filename2, SIZE);
file2.open(filename2);
if(!file2.is_open())
{
cout << "You typed the wrong file name \n" << filename << " can't be opened. Figure it out dude \n";
cout << "Peace out \n";
exit(EXIT_FAILURE);
}
filename2 << "T V H" << endl;
double dt;
double b;
double A;
double mo;
double mf;
file >> dt;
cout << "dt= " << dt << " s" <<endl;
file >> b;
cout << "b= " << b << " N/s^2" <<endl;
file >> A;
cout << "A= " << A << " m^2" <<endl;
file >> mo;
cout << "mi= " << mo << " kg" <<endl;
file >> mf;
cout << "mf= " << mf << " kg" <<endl;
double T1[4];
heightwithT(dt, b, A, mo, mf, T1, filename2);
filename2 << "Height after Thrust = " << T1[0] << "m" << endl;
filename2 << "Velocity after Thrust = " << T1[1] << "m/s" << endl;
filename2 << "Your max height = " << T1[2] << "m" << endl;
filename2 << "The total time = " << T1[3] << "s" << endl;
file.close();
file2.close();
}
return 0;
}






In function main() you have
 
    filename2 << "Height after Thrust = " << T1[0] << "m" << endl;

which should be
 
    file2 << "Height after Thrust = " << T1[0] << "m" << endl;


Similarly the parameter passed to function heightwithT() should be file2, not filename2.

Inside function heightwithT(), you don't need the ampersand on these lines:
&filename2 << t << " " << v << " " << h << endl;
should look like:
filename2 << t << " " << v << " " << h << endl;

... though you should probably change the variable name to file2 in order to reflect the fact that it represents the output stream, not the name of the file.

Topic archived. No new replies allowed.