weather balloon with peak
#include <stdio.h>
#define FILENAME "balloon1.txt"
float altitude, velocity, stime, etime, increments, n;
int main(void){
//get variables
printf("Enter start and end time in hours: \n");
scanf(" %f %f", &stime, &etime);
printf("Enter increment in hours: \n");
scanf(" %f", &increments);
FILE *balloon;
/* Open output file. */
balloon = fopen(FILENAME,"w");
fprintf(balloon, "Time Altitude Velocity");
//printf("1");
if (stime > 48 || etime > 48)
{
printf( "Please enter a time less than 48 hours \n");
}
//printf("2");
else if (increments <= 0)
{
printf("Please input an increment greater than 0");
}
//printf("3");
else
{
float peak = 0, tpeak = 0;
//find altitude and velocity
for (n = stime; n <= etime; n +=increments)
{
altitude = -0.12*(n*n*n*n) + 12*(n*n*n) - 380*(n*n) + 4100*(n) + 220;
velocity = -0.48*(n*n*n) + 36*(n*n) - 760*n + 4100;
fprintf(balloon, " %.2f hours %.2f m %.2f m/s \n", n, altitude, velocity);
if (altitude > peak)
{
peak = altitude;
tpeak = n;
}
}
fprintf(balloon, "Peak altitude: %.2f m %.2f hours", peak, tpeak);
}
//close file
fclose(balloon);
return 0;
}
data gotten with peak with time on the bottom

Comments
Post a Comment