Question: I have the following code, and when I try to return the value of y to my altitude function, the resulting altitude function results in

I have the following code, and when I try to return the value of y to my altitude function, the resulting altitude function results in a 0. I had checked to ensure that the computation is occuring correctly of which it is, although the return function seems to not be returning the correct value for whatever reason. this is in c++

void hydrogen(double x, double y) { double time = x; double altitude = y;

const double cA = -0.12; const double cB = 12.0; const double cC = -380.0; const double cD = 4100.0; const double cE = 220;

double part1 = 0.0; double part2 = 0.0; double part3 = 0.0; double part4 = 0.0;

part1 = (cA * pow(time, 4)); part2 = (cB *pow(time, 3)); part3 = (cC * pow(time, 2)); part4 = (cD * time);

altitude = (part1 + part2 + part3 + part4 + cE ); y = altitude; cout << altitude << " "; return (y); }

and in my main function I have the function call of the following.

time and altitude are both double values set to 0.0

hydrogen(time, altitude); // calculates the altitude cout << time << " " << altitude << endl; }

after this code executes, it displays the time correctly, but the altitude does not update. should be a value of 220

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!