HELP PLEASE!

Mar 23, 2016 at 8:24pm
For my c++ class we are to find the coast altitude and burnout altitude of two rockets. We are required to use the specific function prototype. When I run the below program, for altB and altC it shows "-nan(ind)" instead of a numerical value. No idea what I'm doing wrong. Any help would be appreciated!


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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Include Section
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;


// This funtion computes the burnout altitude and the
// coast altitude of a model rocket.
// The first 6 parameter are the input data
// to the function. Parameter 7 and 8 return the results
void computeA	(double massR,	// Rocket Mass (g)
		 double massE,	// Engine Mass (g)
		 double massP,	// Propellant Mass (g)
		 double dia,	// Diameter of Rocket (mm)
		 double advTh,	// Avg thrust of Engine (N)
		 double burnD,	// Burn Duration (s)
		 double& altB,	// Burnout Altitude (m)
		 double& altC);	// Coast Altitude (m)

const double density = 1.2;		// kg/m^3
const double cd = .75;			// drag coefficient of stndrd rocket
const double gravity = 9.8;		// gravity on earty
const double pi = 3.14;			// constant variable for PI


double avg_mass;			// average mass during boost phase of rocket
double k;				// half atmospher density*drag coeff*area
double vb;				// burnout velocity
double area;				// area of the rocket 
double avgTh;				// Thrust of engine in Newtons
double coastmass;


// Main Program
int main()
{
	// constants


	// Variable Declarations

	double massR;		// the mass of the rocket in grams
	double massE;		// the mass of the engine in grams
	double massP;		// mass of the propelland in grams
	double avgTh;		// Thrust of engine in Newtons
	double burnD;		// burn duration of the engine
	double dia;		// diameter of rocket in mmt
	char good;						// loop input answer

	double altB;
	double altC;

	// Output Identification

	system("CLS");
	cout << "In Class #7 - "
		<< "Rocket Burnout Velocity\n\n";


	// This funtion computes the burnout altitude and the
	// coast altitude of a model rocket.
	// The first 6 parameter are the input data
	// to the function. Parameter 7 and 8 return the results
	
	
	do {
	//
	// Get rocket sample data
	//

	cout << "Enter the mass of the rocket (grams) => ";
	cin >> massR;
	cout << "Enter the mass of the engine (grams) => ";
	cin >> massE;
	cout << "Enter the mass of the propellant (grams) => ";
	cin >> massP;
	cout << "Enter the diameter of the rocket (in millimeters) => ";
	cin >> dia;
	cout << "Enter the average thrust of the engine (Newtons) => ";
	cin >> avgTh;
	cout << "Enter the burn duration of the engine (seconds) => ";
	cin >> burnD;

	// Calculation conversions
	computeA(massR, massE, massP, dia, avgTh, burnD, altB, altC);

cout << fixed << setprecision(1) << endl;
cout << endl;
cout << "The burnout altitude is " << altB << " meters/second." << endl;
cout << "The coast altitude is " << altC << " meters/second." << endl;
cout << "Would you like to run the program again (Y or N)? ";
cin >> good;
cout << endl;
cout << endl;
	} while (good == 'y');


cout << "\n\nEnd Program.\n";

	return 0;
}
void computeA(double massR,	// Rocket Mass (g)
	double massE,	// Engine Mass (g)
	double massP,	// Propellant Mass (g)
	double dia,	// Diameter of Rocket (mm)
	double advTh,	// Avg thrust of Engine (N)
	double burnD,	// Burn Duration (s)
	double& altB,	// Burnout Altitude (m)
	double& altC)	// Coast Altitude (m)
{
	massR = massR / 1000;
	massE = massE / 1000;
	massP = massP / 1000;	
	dia = dia / 1000;			
	dia = (dia / 2);
	avg_mass = massR + massE - (massP * .5);
	coastmass = massR + massE - massP;
	area = pi * (dia*dia);
	k = ((.5 * 1.2) * .75 * area);
	vb = sqrt((avgTh - (avg_mass*gravity)) / k) * tanh((burnD / avg_mass)
		* sqrt(k * (avgTh - avg_mass*gravity)));
	altB = (avg_mass / k) * log(cosh((burnD / avg_mass)*sqrt(k*(avgTh - avg_mass*area))));
	altC = (coastmass / (2 * k))*log(((k*(vb*vb)) / (coastmass*area)) + 1);
}
Last edited on Mar 23, 2016 at 8:40pm
Mar 23, 2016 at 9:05pm
Do not doublepost. Other thread: http://www.cplusplus.com/forum/beginner/187378/
Topic archived. No new replies allowed.