I have this assignment due in 2 hours and I can't figure out why it is not giving me any output. When I don't set the counters and accumulators to 0 it works, but when I do it doesn't!
Here is the code:
Code:
#include<stdlib.h>
#include<stdio.h> //standard library definitions
#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
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
int poolWater; //amount of water in pool in gallons
int balloonNumThrown; //number of balloons "thrown"
int balloonNumHit; //number of balloons that "hit" the pool
double hitPercentage; //percentage of balloons that "hit" the pool
balloonNumHit=0;
balloonNumThrown=0;
poolWater=0;
/*balloonDiam=rand()%(MAX_DIAM-MIN_DIAM+1)+MIN_DIAM;
balloonLaunchAngle=(double)rand()/RAND_MAX*(MAX_THETA-MIN_THETA+1)+MIN_THETA;
balloonLaunchVelocity=(double)rand()/RAND_MAX*(MAX_VEL-MIN_VEL+1)+MIN_VEL;
throwersHeight=(double)rand()/RAND_MAX*(MAX_THR_HT-MIN_THR_HT+1)+MIN_THR_HT;*/
srand(time(NULL));
while(poolWater<CAPACITY)
{
balloonDiam=rand()%(MAX_DIAM-MIN_DIAM+1)+MIN_DIAM;
balloonLaunchAngle=(double)rand()/RAND_MAX*(MAX_THETA-MIN_THETA+1)+MIN_THETA;
balloonLaunchVelocity=(double)rand()/RAND_MAX*(MAX_VEL-MIN_VEL+1)+MIN_VEL;
throwersHeight=(double)rand()/RAND_MAX*(MAX_THR_HT-MIN_THR_HT+1)+MIN_THR_HT;
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==35)
{
poolWater=poolWater+balloonWater;
balloonNumHit++;
}
balloonNumThrown++;
}
hitPercentage=(balloonNumHit/balloonNumThrown)*100;
printf("balloon diameter:%d\n", balloonDiam);
// printf("balloon Launch Angle:%f\n", balloonLaunchAngle);
// printf("balloon Launch Velocity:%f\n", balloonLaunchVelocity);
///printf("Throwers Hiehgt:%f\n", throwersHeight);
//printf("Balloon num thrown: %d\n", balloonNumThrown);
// printf("balloonNumHit: %d\n", balloonNumHit);
//printf("Distance Balloon Traveled: %f\n", distanceTraveled);
printf("%d balloons hit the pool.\n", balloonNumHit);
printf("%d balloons were thrown.\n", balloonNumThrown);
printf("%.2f %% balloons hit the pool", hitPercentage);
return(0);
}