My Program for School. Help?

This is a discussion on My Program for School. Help? within the C Programming forums, part of the General Programming Boards category; Am i using boolean values correctly? our professor wanted boolean value use for the if and else statements. Other comments ...

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    4

    My Program for School. Help?

    Am i using boolean values correctly? our professor wanted boolean value use for the if and else statements. Other comments and suggestions welcome. thanks.

    Code:
    #include <stdio.h>
    #include <math.h>
    #define GRAVITY 9.8
    #define LIMIT 500
    #define SEC 5
    
    
    double calcTime(double height);
    double calcShotDistance(double time, double velocity);
    double getDoubleHeight();
    double getDoubleShipWidth();
    double getDoubleVelocity();
    double getDoubleShipDistance();
    int i........(double shipWidth, double shipDistance, double distance);
    int isDistance(double distance);
    int isTime(double time);
    
    
    int main()
    {         
            double height, velocity, shipWidth, shipDistance, time, distance;
            int boom, far, timeToHit;
             
            height = getDoubleHeight();
            shipDistance = getDoubleShipDistance();
            shipWidth = getDoubleShipWidth();
            velocity = getDoubleVelocity();
            time = calcTime(height);
            distance = calcShotDistance(time, velocity);
            boom = i........(shipWidth, shipDistance, distance);
            far = isDistance(distance); 
            timeToHit = isTime(time);
    
    
            if((boom == 1) && (far == 1))
            {
            printf("I think you hit China!!!\n");
            printf("Distance of ball: %.6f meters\n", distance);
            printf("Direct hit!!!\n");
            }
            else if((boom == 1) && (far == 0) && (timeToHit == 1))
            {
            printf("Look out beloooooooooooooooooooooooooooow!\n");
            printf("Distance of ball: %.6f meters\n", distance);
            printf("Direct hit!!!\n");
            }
            else if((boom == 0) && (far == 1))
            {
            printf("I think you hit China!!!\n");
            printf("Distance of ball: %.6f meters\n", distance);
            printf("You missed!\n");
            }
         else if ((boom == 0) && (far == 0) && (timeToHit == 1))
            {
            printf("Look out beloooooooooooooooooooooooooooow!\n");
            printf("Distance of ball: %.6f meters\n", distance);
            printf("You missed!\n");
            }
            else if((boom == 1) && (far == 0) && (timeToHit == 0))
            {
            printf("Distance of ball: %.6f meters\n", distance);
            printf("Direct hit!!!\n");
            }
            else
            {
            printf("Distance of ball: %.6f meters\n", distance);
            printf("You missed!\n");
            }
    
    
            return 0;
    }
    
    
    int isTime(double time)
    {
            if (time > SEC)
            {
            return 1;
            }
            else
            {
            return 0;
            }
    }
    
    
    int isDistance(double distance)
    {
            if (distance > LIMIT)
            {
            return 1;
            }
            else
            {
            return 0;
            }
    }
    
    
    int i........(double shipWidth, double shipDistance, double distance)
    {
            if((distance < shipDistance + (shipWidth / 2.0)) && (distance > shipDistance - (shipWidth / 2.0)))
            {
            return 1;
            }
            else
            {
            return 0;
            }
    }
    
    
    double getDoubleHeight()
    {
            double height;
            printf("Enter the height of the cliff (meters): ");
            scanf("%lf", &height);
            return height;
    }
    
    
    double getDoubleVelocity()
    {
            double velocity;
            printf("Enter the velocity of the cannon ball (meters/second): ");
            scanf("%lf", &velocity);
            return velocity;
    }
    
    
    double calcShotDistance(double time, double velocity)
    {
            double distance = time*velocity;
            return distance;
    }
                         
    
    
    double getDoubleShipWidth()
    {
            double shipWidth;
            printf("Enter the width of the ship (meters): ");
            scanf("%lf", &shipWidth);
            return shipWidth;
    }
    
    
    double getDoubleShipDistance()
    {
            double shipDistance;
            printf("Enter the distance of the ship from the cliff (meters): ");
            scanf("%lf", &shipDistance);
            return shipDistance;
    }
    
    
    double calcTime(double height)
    {
            double time = sqrt(height / (GRAVITY / 2.0));
            return time;
    }

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    i'm not shure but I think your prof wants somethinge like
    Code:
            if( boom  && far )
            {
                ....
            }
            else if(  boom  &&  ! far  && timeToHit )
            {
                ...
            }
                 ....
    Kurt

  3. #3
    Registered User
    Join Date
    Apr 2013
    Posts
    4
    Oh right! i remember learning that. thank you for your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. School
    By Annonymous in forum C Programming
    Replies: 6
    Last Post: 06-14-2011, 12:04 PM
  2. School
    By prog-bman in forum A Brief History of Cprogramming.com
    Replies: 43
    Last Post: 08-31-2004, 09:46 AM
  3. help with a program for school
    By ssjnamek in forum C++ Programming
    Replies: 17
    Last Post: 01-14-2003, 08:26 PM
  4. school org's
    By adamviper in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-04-2002, 10:58 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21