-2

Here is my full code. I keep getting zero for my equations no matter what i do. Any help would be greatly appreciated.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
int x, y;
float a,t;
//Inputs
printf("What is the speed that the jet is traveling in km/hr? \nWhat is the distance traveled in meters? \n");
scanf("%d , %d", &x, &y );


//Calculations

a = x * 1 / 60 * 1 / 60 * 1 / 60 * 1000 ;

t = sqrt( y * a / 2  ) ;

//Outputs
printf("The acceleration of the jet is %f meters per second squared. \n", a);
printf("The time it takes for the jet to reach takeoff speed is %f seconds. \n", t);

return 0;
}
  • 1
    `x` and `y` need to be `float`, too. – deamentiaemundi Sep 28 '16 at 00:12
  • You may want to change your integer division into floating point division. Adding a single dot after the 60's will take care of that (`60.`). –  Sep 28 '16 at 00:12
  • @deamentiaemundi not necessarily, if (for some reason) you want to enforce integer speeds. The latter is not recommended though. –  Sep 28 '16 at 00:13
  • 1 / 60 is 0; multiply by 0 and the result is zero. Use decimal points to indicate floating point constants: `1.0 / 60.0` for example (I prefer the trailing 0; not everyone cares). – Jonathan Leffler Sep 28 '16 at 00:41
  • I added the decimals behind the 60s to indicate floating point constants. I'm now getting an output. Thanks – jwloszek Sep 28 '16 at 00:44

1 Answers1

0

Your first equation is equivalent to

a = ((((((x * 1) / 60) * 1) / 60) * 1) / 60) * 1000;

ie;

a = (x/(60*60*60)) * 1000;

or

a = (x/(216000)) * 1000;

Even though your a is a float, RHS of your equation is doing integer division.

Hence any value less than 216000 assigned to x will result in 0.

aneesh jose
  • 381
  • 2
  • 8