Stuck in an infinite do while loop

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

#include "stdafx.h"
#include "stdio.h"
#include "math.h"

int main()
{
double s;
double i;
double e;
double a; //altitude
double v; //velocity
double a_max = 0;
double s_max = 0;

printf("Enter the start time: ");
scanf("%lf", &s); //s represents start time

printf("Enter the time increment: ");
scanf("%lf", &i); //i represents increment

printf("Enter the end time: ");
scanf("%lf", &e); //e represents end time

printf("Weather Balloon Information\n");
printf("Time\tHeight\tVelocity\n");
printf("hrs\tmeters\tmeters/s\n");

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);

}
Last edited on
Your while loop won't end if i is <= 0...other then that, I don't see anything completely wrong...
the numbers i'm supposed to be able to input are s=0 i=1 e=3 and s=0 i=3 e=12.
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?
Topic archived. No new replies allowed.