Balloon Code
#include <stdio.h>
#include <math.h>
#define PI 3.141593
#define FILENAME "data.txt"
int main(void)
{
/* Declare variables. */
double t;
double inc_time;
double altitude, velocity;
int x =0;
int i;
int end, start, status;
float al, vel;
char m;
printf("Enter start time (hrs) and end time\n ");
scanf(" %i %i", &start, &end);
printf("Enter time increment \n");
scanf(" %lf",&inc_time);
while (start >48 || start<0 || end<0|| (end<=start) || end>48 || inc_time>48){
printf("Error: Please input within range 0-48 hrs, and endtime>starttime) \n");
printf("Enter start time (hrs) and end time\n ");
scanf(" %i %i", &start, &end);
printf("Enter time increment \n");
scanf(" %lf",&inc_time);
}
FILE *data;
/* Open output file. */
data = fopen(FILENAME,"w");
fprintf(data, "Altitude Velocity \n");
printf("Altitude Velocity \n");
for (start; start < end; start += inc_time){
t = start;
altitude = -.12*t*t*t*t + 12*t*t*t - 380*t*t + 4100*t + 220;
velocity = -0.48*t*t*t + 36*t*t - 760*t +4100;
fprintf(data," %2.2lf %10.2lf \n", altitude, velocity);
/*printf(" %2.2lf %10.2lf \n", altitude, velocity); */
x = x+1;
}
fclose(data);/* Close file and exit program. */
FILE *dataa;
dataa = fopen("data.txt", "r");
fscanf(dataa, " %c", &m);
for (i = 1; i<x; i++){
fscanf(dataa, "%lf %lf", &al, &vel);
printf(" %2.2lf %10.2lf", al, vel);
}
fclose(dataa);
return 0;
}
#include <math.h>
#define PI 3.141593
#define FILENAME "data.txt"
int main(void)
{
/* Declare variables. */
double t;
double inc_time;
double altitude, velocity;
int x =0;
int i;
int end, start, status;
float al, vel;
char m;
printf("Enter start time (hrs) and end time\n ");
scanf(" %i %i", &start, &end);
printf("Enter time increment \n");
scanf(" %lf",&inc_time);
while (start >48 || start<0 || end<0|| (end<=start) || end>48 || inc_time>48){
printf("Error: Please input within range 0-48 hrs, and endtime>starttime) \n");
printf("Enter start time (hrs) and end time\n ");
scanf(" %i %i", &start, &end);
printf("Enter time increment \n");
scanf(" %lf",&inc_time);
}
FILE *data;
/* Open output file. */
data = fopen(FILENAME,"w");
fprintf(data, "Altitude Velocity \n");
printf("Altitude Velocity \n");
for (start; start < end; start += inc_time){
t = start;
altitude = -.12*t*t*t*t + 12*t*t*t - 380*t*t + 4100*t + 220;
velocity = -0.48*t*t*t + 36*t*t - 760*t +4100;
fprintf(data," %2.2lf %10.2lf \n", altitude, velocity);
/*printf(" %2.2lf %10.2lf \n", altitude, velocity); */
x = x+1;
}
fclose(data);/* Close file and exit program. */
FILE *dataa;
dataa = fopen("data.txt", "r");
fscanf(dataa, " %c", &m);
for (i = 1; i<x; i++){
fscanf(dataa, "%lf %lf", &al, &vel);
printf(" %2.2lf %10.2lf", al, vel);
}
fclose(dataa);
return 0;
}
Comments
Post a Comment