/* Preprocessor directives */ #include <stdio.h> #include <math.h> #define input
ID: 671874 • Letter: #
Question
/* Preprocessor directives */
#include <stdio.h>
#include <math.h>
#define inputfile "c:\engr 200\launch.txt"
#define outputfile "c:\engr 200\balloon_results.txt"
/* Main Function */
int main(void)
{
/* Declare and initialize variables */
double altitude(int time);
double velocity(int time);
int nhours,time;
double baltitude,bvelocity;
FILE *launch, *balloon_results;
/* Open files */
launch = fopen(inputfile,"r");
balloon_results = fopen(outputfile,"w");
/* Print output headings */
printf(" ---------------------------------- "
" WEATHER BALLOON PROGRAM "
"---------------------------------- "
" TIME ALTITUDE VELOCITY "
" (hours) (meters) (m/hr)");
fprintf(balloon_results," ---------------------------------- "
" WEATHER BALLOON PROGRAM "
"---------------------------------- "
" TIME ALTITUDE VELOCITY "
" (hours) (meters) (m/hr)");
/* Verify input file and read control number */
if(launch == NULL)
{
printf(" Error opening input file.");
printf(" Press Enter to quit. ");
getchar(); getchar();
return 0;
}
else
{
/* Read control number */
fscanf(launch,"%i",&nhours);
/* Compute and print results */
for(time=0;time<=nhours;time++)
{
fscanf(launch,"%i",&time);
baltitude=altitude(time);
bvelocity=velocity(time);
printf(" %2.0f %5.0f %5.0f ",
time,baltitude,bvelocity);
fprintf(balloon_results," %2.0f %5.0f %5.0f ",
time,baltitude,bvelocity);
}
}
/* Close the input file */
fclose(launch);
fclose(balloon_results);
/* Exit the program */
printf(" Press Enter to quit. ");
getchar(); getchar();
return 0;
}
/**********************************************************************
This function will calculate the altitude and velocity of the balloon
after receiving the time.
**********************************************************************/
double altitude(int time)
{
/* Declare variables */
double balloon_altitude;
/* Compute */
balloon_altitude=-0.12*pow(time,4)+12.0*pow(time,3)
-380.0*pow(time,2)+4100.0*time+220.0;
/* Return balloon altitude */
return balloon_altitude;
}
/********************************************************************/
double velocity(int time)
/* Declare variables */
{
double balloon_velocity;
/* Compute */
balloon_velocity=-0.48*pow(time,3)+36.0*pow(time,2)-760.0*time+4100.0;
/* Return balloon velocity */
return balloon_velocity;
}
program runs but the output time only shows 0 instead of 0 to 12 as desired. Please help
Explanation / Answer
I have solve the problem , there will be no repeated 0 and solution will be printed as you formated.
all the best
Program
/* Preprocessor directives */
#include <stdio.h>
#include <math.h>
#define inputfile "c:\engr 200\launch.txt"
#define outputfile "c:\engr 200\balloon_results.txt"
/* Main Function */
int main(void)
{
/* Declare and initialize variables */
double altitude(int time);
double velocity(int time);
int nhours,time;
double baltitude,bvelocity;
FILE *launch, *balloon_results;
/* Open files */
launch = fopen(inputfile,"r");
balloon_results = fopen(outputfile,"w");
/* Print output headings */
printf(" ---------------------------------- ");
printf(" WEATHER BALLOON PROGRAM ");
printf("---------------------------------- ");
printf(" TIME ALTITUDE VELOCITY ");
printf(" (hours) (meters) (m/hr)");
fprintf(balloon_results," ---------------------------------- ");
fprintf(balloon_results," WEATHER BALLOON PROGRAM ");
fprintf(balloon_results,"---------------------------------- ");
fprintf(balloon_results," TIME ALTITUDE VELOCITY ");
fprintf(balloon_results," (hours) (meters) (m/hr)");
/* Verify input file and read control number */
if(launch == NULL)
{
printf(" Error opening input file.");
printf(" Press Enter to quit. ");
getchar(); getchar();
return 0;
}
else
{
/* Read control number */
fscanf(launch,"%i",&nhours);
/* Compute and print results */
printf(" ");
for(time=0;time<=nhours;time++)
{
fscanf(launch,"%i",&time);
baltitude=altitude(time);
bvelocity=velocity(time);
printf(" %2d %5.0lf %5.0lf ",
time,baltitude,bvelocity);
fprintf(balloon_results," %2d %5.0lf %5.0lf ",
time,baltitude,bvelocity);
}
}
/* Close the input file */
fclose(launch);
fclose(balloon_results);
/* Exit the program */
printf(" Press Enter to quit. ");
getchar(); getchar();
return 0;
}
/**********************************************************************
This function will calculate the altitude and velocity of the balloon
after receiving the time.
**********************************************************************/
double altitude(int time)
{
/* Declare variables */
double balloon_altitude;
/* Compute */
balloon_altitude=-0.12*pow(time,4)+12.0*pow(time,3)
-380.0*pow(time,2)+4100.0*time+220.0;
/* Return balloon altitude */
return balloon_altitude;
}
/********************************************************************/
double velocity(int time)
/* Declare variables */
{
double balloon_velocity;
/* Compute */
balloon_velocity=-0.48*pow(time,3)+36.0*pow(time,2)-760.0*time+4100.0;
/* Return balloon velocity */
return balloon_velocity;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.