outfiling using c-string

i want to give the user the option to either pring to the screen or print to the file. I was able to succesfully print to the string but when the user choose to print to a file i get an error message. can some1 please help me out

void dynamics :: get_var()
{
cout << "Please enter the height: ";
cin >> h;
cout << "\nPlease enter the initial velocity: ";
cin >> Vo;
cout << "\nPlease enter the angle: ";
cin >> Angle;
cout << endl;
}

//Function using bool to allow the user to re-enter the values if an error was made.
bool dynamics :: check_var()
{
if(Angle <=0 || h <=0 || Vo <=0)
{
cout << "Please make sure your values are greater than 0." << endl;
return false;
}

if(Angle >= 90)
{
cout << "Please enter an angle between 0 and 90 degrees." << endl;
return false;
}
else return true;
}

//Function to convert to degrees
double dynamics :: convert_deg(double ang)
{
const double PI=acos(-1.0);
return ang*PI/180;
}

//Function that allows the user to choose where they want to see their outputs.
void dynamics :: print_where()
{
cout << "Would you like to print to screen (S) or file (F): ";
cin >> response;
if(response == 'S' || response == 's')
{
print_to_screen();
}
else if(response == 'F' || response == 'f')
{
print_to_file();
}
}

//Function that allows the user to name their data file and send the information to it.
void dynamics :: print_to_file()
{
cout << "What would you like the file name to be(no spaces): ";
cin >> file_name;
ofstream outfile(file_name.c_str());
ofstream outfile("K:\\EGR125\\

for (int i = 0 ; i<=20; i++)
{
outfile << fixed << setprecision(3) << array_time[i] << ","
<< setprecision(1) << array_x[i] << "," << array_y[i] << endl;
}

}


void dynamics::set_time()
{
double a = .5*-9.81;
double b = Vo*sin(convert_deg(Angle));
double c = h;
double inner_calc = sqrt((pow(b,2))-(4*a*c));
double calc1 = ((-1*b) - inner_calc)/(2*a);
double calc2= ((-1*b) + inner_calc)/(2*a);
if (calc1 < 0)
{
time = calc2;
}
else
{
time = calc1;
}

}
//Functin to set maximum distance
void dynamics :: set_max_dist ()
{
max_dist = Vo*cos(convert_deg(Angle))*time;

}
//Function to set maximum height
void dynamics :: set_max_height ()
{
max_height = h - ((pow(Vo*sin(convert_deg(Angle)),2))/(2*-9.81));

}
//Function using looping array to set velocities to produce the data table.
void dynamics::set_arrays()
{
double x = max_dist/21;
double Vyo = Vo*sin(convert_deg(Angle));
double Vxo = Vo*cos(convert_deg(Angle));
int i;
for (i=0; i<=20;i++)
{
array_x[i] = (i+1)*x;
}
for (i=0; i<=20;i++)
{

array_time[i] = array_x[i]/Vxo;
array_y[i]= Vyo* array_time[i] + (.5*9.81*pow(array_time[i],2));
}

}

//Function for screen output table.
void dynamics::print_to_screen()
{

cout <<" time, t (s) distance, x (m) height, y (m) " << endl;
cout << "-----------------------------------------------------------" << endl;
for (int i = 0 ; i<=20; i++)
{
cout << fixed << setprecision(3) << setfill(' ')
<< setw(10)<< array_time[i]
<< setprecision(1) << setw(6)<< "|" << setw(11) << array_x[i]
<<setw(7)<< "|" << setw(10)<< array_y[i] << endl;
}
}
int main ()
{
dynamics project;

project.get_var();
//bool output;
while(project.check_var() == false)
{
project.get_var();
}

project.set_time();
project.set_max_dist();
project.set_max_height();
project.set_arrays();
project.print_where();
project.print_to_file();

system("pause");
return 0;
}
Topic archived. No new replies allowed.