# logic error

This is a discussion on logic error within the C Programming forums, part of the General Programming Boards category; Code: I am using function to find the range of a projectile, but whenever I try to run the program ...

1. ## logic error

Code:
```I am using function to find  the range of a projectile, but whenever I try to run the program it will return zero 0.00. Can someone help me solve this logic problem. thanks in advance.

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

double distance (double a, double v, double g);
int square(int y);
int main(void)
{
double v, d, h, datha, degrees, velocity;
const int pi=3.14159265359;
const double g= 9.8;

printf(" enter the angle in degrees");
scanf("%.2f", &degrees);
datha = degrees * pi/180;
printf("Enter the initial veloity\n");
scanf("%.2f\n", &v);
velocity = square(v);
d= distance(datha, velocity,g);
printf("the reange of the projectile was %.2f", d);
return 0;
}
int square(int y){
return pow(y,2);
}
double distance(double a, double v, double g ){
return v *sin(2*a)/g;
}```

2. Well for starters int's can't contain fractional parts:
Code:
` const int pi=3.14159265359; //????`
Second why are you using a floating point function (pow) to return an int?

Third you are misusing the scanf() function. You need to insure the format specifier matches the variable. Your's don't match, "%f" is the specifier for a float, not a double.

Note I didn't look for any "logic" errors, the syntax errors may be your problem. You may want to insure your compiler is generating the maximum number of warnings and never ignore warnings.

Jim

3. it work, I appreciated all your help and time thxxx :-P