Help with a class project

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.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include<iostream>

#include<iomanip>

#include<fstream>

using namespace 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;

}
Last edited on
While probably not the actual problem you can simplify the following snippet:
1
2
3
4
5
6
7
8
	/***********create ifstream******************/
	ifstream suspension_system;

	/**************open file**********************/
	suspension_system.open("P:\\Private\\ProjData.txt");

	/***************check file***********************/
	if (suspension_system.fail())


To the following:
1
2
3
4
5
	/***********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.

Last edited on
Input:
car_A
1000000 180000 9800 19 1250 0.0 0.5 .0025
car_B
1000000 175000 9800 20 1620 0.0 0.1 .005
car_C
1000000 130000 9800 20 1580 0.0 0.2 .005
car_D
1000000 100000 9800 21 1870 0.0 0.1 .002

out:
Passive Suspension System

Car | Tire| Spring | Dash-Pot | Wheel M | Car M | Start T | End T | Time Inc
---------------------------------------------------------
-9.25596e+061
Press any key to continue . . .
Your problem is that you have defined car_name as a single char instead of a string.

Last edited on
Topic archived. No new replies allowed.