i'm trying to do my third project for c++ and i'm stuck in an infinite loop where the values of v and a appear to be a(i) and v(i). everything else seems to be working except for the do while loop. can anyone help me out, it's due at 9:00 a.m tomorrow.
the problem is: Print a table of the altitude and the velocity for this balloon using units of meters and meters per second. User must enter the start time, the increment in time between lines of the table and an ending time. All time values must be less than 48 hours. In addition to the table print the peak altitude and the corresponding time
do
{
a = -0.12*pow(s,4) + 12*pow(s,3) - 380*pow(s,2) + 4100*pow(s,1) + 220;
v = -0.48*pow(s,3) + 36*pow(s,2) - 760*pow(s,1) + 4100;
printf("%.2lf\t%.2lf\t%.2lf\n", s, a, v/3600); //Could be the problem
if (a > a_max)
{
a = a_max;
s = s_max;
}
s = s + i; //Could be the problem
}
while (s <= e); //Could be the problem
printf("\nThe maximum balloon height was %.2lf\n", a_max);
printf("It occured at %.21f", s_max);
Not sure if this is of use now, since it's now past 9:00am tomorrow, but you are stuck in an infinite loop because you are always resetting s = s_max, ie setting it to 0. So everytime you incrementing it by i, you are incrementing it from 0 to i. I'm thinking you did not attend to set a_max and s_max to zero.
i set a_max and s_max to zero in order to record the largest value for a and s, which is what i'm trying to do with the if loop. i notice if i disable the if loop, the program works correctly. so now my question is, what is the correct way to implement the if loop in order to record a_max and s_max?