Code:
#include<stdio.h> //standard library definitions
#include<stdlib.h>
#include<math.h> //math definitions
#define BAL_HEIGHT 12 //balcony height in feet
#define G 32 //gravitational acceleration in ft/s2
#define PI 3.14159
#define POOL_CENTER 35 //distance to the center of pool
#define MIN_THETA 5 //minimum balloon launch angle in degrees
#define MIN_VEL 1 //minimum balloon launch velocity in ft/sec
#define MIN_THR_HT 4.5 //minimum height of thrower in feet
#define MAX_THETA 85 //maximum balloon launch angle in degrees
#define MAX_VEL 30 //maximum balloon launch velocity in ft/sec
#define MAX_THR_HT 7.0 //maximum height of thrower in feet
#define MIN_DIAM 3 //minimum diameter of balloon in inches
#define MAX_DIAM 9 //maximum diameter of balloon in inches
#define CAPACITY 7 //pool capacity in gallons
#define FILENAME "balloonValues.txt" //input data file
int main()
{
double balloonLaunchAngle; //input: angle in degrees
double balloonLaunchVelocity; //input: launch velocity in ft/sec
double throwersHeight; //input: user's height plus balcony height in feet
double distanceTraveled; //output: distance the balloon traveled in feet
double part1, part2, part3; //distance formula: partial result holders
int balloonDiam; //ballon diameter in inches
double balloonWater; //amount of water in balloon in gallons
double poolWater; //amount of water in pool in gallons
int balloonNumThrown; //number of balloons "thrown"
int balloonNumHit; //number of balloons that "hit" the pool
FILE *balloonValues;
balloonValues=fopen(FILENAME,"r");
if(balloonValues==NULL)
{
printf("Error opening input file.");
}
else
{
poolWater=0;
balloonNumThrown=0;
balloonNumHit=0;
srand(time(NULL));
while((fscanf(balloonValues,"%f %f %f %d", &balloonLaunchAngle, &balloonLaunchVelocity, &throwersHeight, &balloonDiam))!=EOF)
{
balloonNumThrown++;
switch(balloonDiam)
{
case 3: balloonWater=0.1;
break;
case 4: balloonWater=0.2;
break;
case 5: balloonWater=0.3;
break;
case 6: balloonWater=0.55;
break;
case 7: balloonWater=0.8;
break;
case 8: balloonWater=1.25;
break;
case 9: balloonWater=1.7;
break;
}
part1=(balloonLaunchVelocity*cos(balloonLaunchAngle*PI/180.0))/G;
part2=balloonLaunchVelocity*sin(balloonLaunchAngle*PI/180.0);
part3=2*G*(throwersHeight+BAL_HEIGHT);
distanceTraveled=part1*(part2+(sqrt(pow(part2,2)+part3)));
if(distanceTraveled>POOL_CENTER-1 && distanceTraveled<POOL_CENTER+1)
{
poolWater=poolWater+balloonWater;
balloonNumHit++;
}
if(poolWater<CAPACITY)
balloonNumThrown;
}
fclose(balloonValues);
}
printf("%f\n %f \n%f \n%d\n", &balloonLaunchAngle, &balloonLaunchVelocity,
&throwersHeight, &balloonDiam); //threw that in there just to check that I am getting values
printf("%d balloons hit the pool.\n", balloonNumHit);
printf("%d balloons were thrown.\n", balloonNumThrown);
printf("%.2f %% balloons hit the pool.\n", (double)balloonNumHit/balloonNumThrown*100);
printf("The pool was full after balloon #%f", poolWater);
//fclose(balloonValues);
return(0);
the output should look like this...but in the directions it says that everyone will probably have different answer
8 balloons hit the pool.
275 balloons were thrown.
2.91% balloons hit the pool.
The pool was full after balloon #218.
3.00 gallons of water spilled over the edge of the pool. ( I haven't done this one yet)