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\\
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++)
{