I need help with creating a program for a suspension system on a car so far i have read in the data and tried to echo it and it spits out a bunch of garbage numbers. If you could tell me what I'm doing wrong it would be greatly appreciated. Thank you in advance, and I also will most likely have more questions to follow relating to this project.
#include<iostream>
#include<iomanip>
#include<fstream>
usingnamespace std;
int main()
{ /********Variables*******/
char car_name;
//tire spring constant
double tire_spring;
//constant of the spring
double spring_constant;
//dampening constant of the dash-pot
double dash_pot;
//mass of the wheel
double wheel_mass;
//mass of the whole car
double car_mass;
//start of time
double t_start;
//end of time
double t_end;
//incriment of time
double t_incriment;
/***********create ifstream******************/
ifstream suspension_system;
/**************open file**********************/
suspension_system.open("P:\\Private\\ProjData.txt");
/***************check file***********************/
if (suspension_system.fail())
{
cout << " ERROR OPENING FILE!!!!!!!!!!!!!!!!!!\n" << endl;
system ("pause");
return 0;
}
/*********Create Header******************/
cout << " \t\t\tPassive Suspension System\n" << endl;
cout <<"Car | Tire| Spring | Dash-Pot | Wheel M | Car M | Start T | End T | Time Inc"<< endl;
cout << "---------------------------------------------------------" << endl;
/*****************Loop while using data file*********************/
while (!suspension_system.eof())
{ //read in suspension system
suspension_system >> car_name >> tire_spring >> spring_constant >> dash_pot >> wheel_mass >> car_mass >> t_start >> t_end >> t_incriment;
cout << tire_spring << endl;
break;
}
suspension_system.close();
system ("pause");
return 0;
}
/***********create ifstream and open the file******************/
ifstream suspension_system("P:\\Private\\ProjData.txt");
/***************check file***********************/
if (suspension_system) // Check for all errors, not just fail().
To answer the actual question you will need to show a small sample of your input file and the output your program is now producing.
Car | Tire| Spring | Dash-Pot | Wheel M | Car M | Start T | End T | Time Inc
---------------------------------------------------------
-9.25596e+061
Press any key to continue . . .