Day_11

Comment: For this code I didn't finish the last modification,since I couldn't figure it out. David told me that my brackets were confusing and that it needed to be work on. This homework took me a while to figure out, since i wasn't too sure on what to name my header file at first.

Display: the maximum altitude
#include <stdio.h>
#include <math.h>

//Define the name of the file
//#define FILENAME "balloon1.txt"

int main(void)
{

//Declaring variable
double initial_val,increment_val,final_val,time_val,velocity_val,height_val;
FILE *balloon;
//Read the input from the user
balloon=fopen("balloon1.txt","w");
//User input with scan and printf
printf("Enter the values for the table in hours\n");
printf("\nEnter the intial value for time \n");
scanf("%lf", &initial_val);
printf("enter the increment value:\n");
scanf("%lf",&increment_val);
printf("Enter the final value:\n");
scanf("%lf",&final_val);
//Display the heading
if(initial_val>final_val)
{
printf("\nplease reenter the final time to be greater then the inital time\n");
fprintf(balloon,"\nplease reenter the final time to be greater then the inital time\n");
return 0;
}
printf("\n\n Information of Weather Balloon \n");
printf("Time HEight Velocity\n");
printf("hours: Meters: Meters/S: \n");


double max_final_val=0;
//Computing the equations for the weather balloon
for(time_val=initial_val;time_val<=final_val;time_val+=increment_val)
{
//Computing the height
height_val=(-0.12*pow(time_val,4))+(12*pow(time_val,3))-(380*time_val*time_val)+(4100*time_val)+220;
//Computiung the velocity
velocity_val=-.48*pow(time_val,3)+36*time_val*time_val-760*time_val+4100;

if(max_final_val<=height_val)
{
max_final_val=height_val;
}

}
//else
//Print the valuesprint

printf("%lf %lf %lf\n",time_val,height_val,velocity_val/3600);
//Display the time,height, and velocity of weather balloon into a file
fprintf(balloon,"%lf %lf %lf\n",time_val,height_val,velocity_val/3600);


fprintf(balloon,"%lf",max_final_val);
printf("Corresponding time of maximum altitude");

//close the file
fclose(balloon);
return 0;
}



Display the data sheet:
#include <stdio.h>
#include <math.h>

//Define the name of the file
//#define FILENAME "balloon1.txt"

int main(void)
{

//Declaring variable
double initial_val,increment_val,final_val,time_val,velocity_val,height_val;
FILE*balloon;
//Read the input from the user
balloon=fopen("balloon1.txt","w");
//User input with scan and printf
printf("Enter the values for the table in hours\n");
printf("\nEnter the intial value for time \n");
scanf("%lf", &initial_val);
printf("enter the increment value:\n");
scanf("%lf",&increment_val);
printf("Enter the final value:\n");
scanf("%lf",&final_val);
if(initial_val>final_val)
{
printf("\nplease reenter the final time to be greater then the inital time\n");
fprintf(balloon,"\nplease reenter the final time to be greater then the inital time\n");
return 0;
}
//Display the heading
printf("\n\n Information of Weather Balloon \n");
printf("Time HEight Velocity\n");
printf("hours: Meters: Meters/S: \n");

//Computing the equations for the weather balloon
for(time_val=initial_val;time_val<=final_val;time_val+=increment_val)
{
//Computing the height
height_val=(-0.12*pow(time_val,4))+(12*pow(time_val,3))-(380*time_val*time_val)+(4100*time_val)+220;
//Computiung the velocity
velocity_val=-.48*pow(time_val,3)+36*time_val*time_val-760*time_val+4100;
//int max_final_val
//if(max_final_val>final_val-=1)
//{
//final_val=max_final_val;
//print("%lf\n",max_final_val);
//fprintf(balloon,"%lf",max_final_val);
//}
//else
//Print the values
printf("%lf %lf %lf\n",time_val,height_val,velocity_val/3600);
//Display the time,height, and velocity of weather balloon into a file
fprintf(balloon,"%lf %lf %lf\n",time_val,height_val,velocity_val/3600);

}


//close the file
fclose(balloon);
return 0;

}







Comments

Popular posts from this blog

Day_13

Day 18 WH