1. ## Help asap!

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);
}```

2. Well... you're not getting output because your printf() statements are mostly commented out...
You're probably getting wrong answers because your variables are doubles but you're trying to print floats.

3. I added those printf's in there but commented them out temporarily so I know why I'm not seeing those. I thought about that...which double variables are you referring to?

4. balloonLaunchAngle for one; you declare that as a double, but the %f in printf expects a float.

Your balloonHitPercentage won't work properly either because you are performing integer division. You want to force floating point division, like this:
Code:
`hitPercentage=( (double) balloonNumHit/balloonNumThrown)*100;`

5. Originally Posted by TheBigH
balloonLaunchAngle for one; you declare that as a double, but the %f in printf expects a float.
Actually %f and %lf are the same for printf. The difference matters with scanf.

6. I just looked in my programming book and it says that when using printf of a double use %f
I'm not getting anything at all on my MS-DOS box

7. Ok... just ran this on my own system...

1) you need to add #include <time.h> ... for your srand(time()); call.

2) It's entering an infinite loop... because you initially set poolWater to 0 and the only time you change it's value is if distanceTravelled == 35 ... so you have to find a better way to administer that loop... perhaps on numThrown instead...

3) The switch statement doesn't include all possibilities so it is possible for ballonWater to be used in an uninitialized state.

4) there are a number of conversion errors reported that you should deal with.

Best advice... turn your compiler's warning level all the way up and deal with every line it reports as an item that needs to be fixed.

Lets hope that gets it...

8. Okay, let me do that and see if it works...

10. Originally Posted by tayexdrums
Go back up and re-read post #7 ... how many items does it list?

Really... do them all or don't bother.

11. No need to get hostile!lol
But okay, I need to find a better to change the control variable poolWater instead of using distanceTraveled==35

12. Originally Posted by tayexdrums
No need to get hostile!lol
Hey... you came to us (me) asking for "help ASAP"... and then you flat out ignore the advice you're given?

It is very rare that any of us take posted code and compile it on our own systems...
I've done you a special favor here and you just blew it all off.

Not hostile... getting you to actually read what is offered!

13. I know, i know...I thank you SO much for your assistance no doubt about it. I just think I was reading it so fast that I did what I saw first without thinking about it.

Anyhow, I the poolWater HAS to be dependent upon whether or not the balloon hit the pool because that is the only way the water level can increase

14. Then switch your while loop to administer on the number of baloons thrown... not the amount of water in the pool... interestingly you are already incrementing that variable at the bottom of the loop... just use it.

15. I got information to appear! but its still not right...however, I think I can figure out why...hopefully.lol
thank you