Thread: logic error

  1. #1
    Registered User
    Join Date
    Mar 2013

    logic error

    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. #2
    Registered User
    Join Date
    May 2010
    Well for starters int's can't contain fractional parts:
     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.

    Last edited by jimblumberg; 03-30-2013 at 11:55 AM.

  3. #3
    Registered User
    Join Date
    Mar 2013
    it work, I appreciated all your help and time thxxx :-P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Possible Logic Error
    By seanksg in forum C Programming
    Replies: 8
    Last Post: 03-14-2011, 06:42 PM
  2. Error in logic
    By Mentallic in forum C Programming
    Replies: 2
    Last Post: 03-28-2010, 08:02 AM
  3. logic Error
    By asmaa in forum C++ Programming
    Replies: 4
    Last Post: 02-13-2009, 10:58 PM
  4. Logic Error...
    By Blackroot in forum C++ Programming
    Replies: 6
    Last Post: 01-28-2006, 06:21 AM
  5. logic error
    By sscook69 in forum C++ Programming
    Replies: 5
    Last Post: 04-07-2002, 06:00 PM