howru

Apr 7, 2008, 11:20 PM

Hi, I need help writing a program. I 'm not a computer major, but I have to take this class for graduating requirements. I have never done programming in my life and this is my first program assignment and I was wondering if someone can help me start it and give me adivce on how to continue it or end it.

Problem: Transported back in time (with your computer) you are in charge of harbor defenses for your city. Using the recently develped length standard, the meter, the cannon master wants to now if a shot fired at a given velocity from his cliff-mounted cannon will hit an enemy ship entering the harbor. In addition to the velocity, he gives you the height of the cliff, the distance from the ship, and the width of the ship. You decide to amaze the general by develping a program to solve the problem.

You can assume that the cannon is mounted horizontally. the ship distance is given from the end of the cannon to the middle of the ship.

Picture: there's a picture,its a cliff with a cannon on top of it and a ship on water. the ship is away from the cliff with a distance x.

the coordinates, to make the x and y axis positive, i just flipped the x and y axis with a upside down half parabola in the fourth quadrant. hope that makes sense. my teacher wants it that way.

to make the problem easier, this is what I did and what my teacher also prefers:

To determine the distance of the shot you must dermine how long it takes the cannon ball to fall from the height of the cliff. the initial downward velocity is zero. Use 9.8 m/s to represent gravity.

Note: I also have to make note of the units when I write my program, when i plug in numbers, i have to come out with something meters. I also need help with that.

The equation my teacher provided us is with is:

then, the distane of the shot=velocity*time

Some specification of the program is that all numerical outputs should be done using %f flag, the all calculations should maintain as much precision as is supported by the C double type in the gcc compiler. Assume all inputs will be greater than zero.

This is how I started mine:

/* calculate the distance of the cannon ball */

#include <stdio.h>

#define GRAVITY 9.8

int main(void)

{

double height > 0

double width > 0

double velocity >0

double time >0

/* Get the height of the cliff */

printf("Enter the height of the cliff (meters): ");

scanf("%f", &height);

/* Get the height of cliff from ship */

printf("Enter the distance of the ship from the cliff(meters): ");

scanf("%f", &height);

/*Get the velocity of the cannon ball */

printf("Enter the velocity of the cannon ball (meters/second): ");

scanf(%f", &velociyt);

/* Get the width of ship */

printf("Enter the width of ship (meters): ");

scanf(%f, &width);

/*Calculate the time of it takes */

time=sqrt[height/(GRAVITY/2)];

/* Calculate the distance of ball */

distance=velocity*time;

/* Print the results */

print("The distance of the cannon ball from the ship is %f.\n", distance);

return(0);

}

My questions and doubts:

1) how do i include the units in my program. did i do it right?

2) on my paper, my teacher gave us an example of a sample run:

enter the height of the cliff (meters): 50

enter the distance of the ship from the cliff (meters):180

Enter the width of the ship(meters): 15

Enter the velocity of he cannon ball (meters/second):

Distance of ball: 175.691055 meters

Direct hit!!!!!!

So after i write my program and compile it, i'm guessing my screen will have

enter the...

enter the...

enter the...

then the teacher plugs in numbers and solves the problems

But on the formula given, it doesn't include all width of the ship. should i put all this variable like the width in my program still?

When my teacher tests each program: he's going to have a set of numbers and he going to type in this number and press enter and it's going to tell him the distance.

so how would i do this. please help. I don't want to fail this class.

Problem: Transported back in time (with your computer) you are in charge of harbor defenses for your city. Using the recently develped length standard, the meter, the cannon master wants to now if a shot fired at a given velocity from his cliff-mounted cannon will hit an enemy ship entering the harbor. In addition to the velocity, he gives you the height of the cliff, the distance from the ship, and the width of the ship. You decide to amaze the general by develping a program to solve the problem.

You can assume that the cannon is mounted horizontally. the ship distance is given from the end of the cannon to the middle of the ship.

Picture: there's a picture,its a cliff with a cannon on top of it and a ship on water. the ship is away from the cliff with a distance x.

the coordinates, to make the x and y axis positive, i just flipped the x and y axis with a upside down half parabola in the fourth quadrant. hope that makes sense. my teacher wants it that way.

to make the problem easier, this is what I did and what my teacher also prefers:

To determine the distance of the shot you must dermine how long it takes the cannon ball to fall from the height of the cliff. the initial downward velocity is zero. Use 9.8 m/s to represent gravity.

Note: I also have to make note of the units when I write my program, when i plug in numbers, i have to come out with something meters. I also need help with that.

The equation my teacher provided us is with is:

then, the distane of the shot=velocity*time

Some specification of the program is that all numerical outputs should be done using %f flag, the all calculations should maintain as much precision as is supported by the C double type in the gcc compiler. Assume all inputs will be greater than zero.

This is how I started mine:

/* calculate the distance of the cannon ball */

#include <stdio.h>

#define GRAVITY 9.8

int main(void)

{

double height > 0

double width > 0

double velocity >0

double time >0

/* Get the height of the cliff */

printf("Enter the height of the cliff (meters): ");

scanf("%f", &height);

/* Get the height of cliff from ship */

printf("Enter the distance of the ship from the cliff(meters): ");

scanf("%f", &height);

/*Get the velocity of the cannon ball */

printf("Enter the velocity of the cannon ball (meters/second): ");

scanf(%f", &velociyt);

/* Get the width of ship */

printf("Enter the width of ship (meters): ");

scanf(%f, &width);

/*Calculate the time of it takes */

time=sqrt[height/(GRAVITY/2)];

/* Calculate the distance of ball */

distance=velocity*time;

/* Print the results */

print("The distance of the cannon ball from the ship is %f.\n", distance);

return(0);

}

My questions and doubts:

1) how do i include the units in my program. did i do it right?

2) on my paper, my teacher gave us an example of a sample run:

enter the height of the cliff (meters): 50

enter the distance of the ship from the cliff (meters):180

Enter the width of the ship(meters): 15

Enter the velocity of he cannon ball (meters/second):

Distance of ball: 175.691055 meters

Direct hit!!!!!!

So after i write my program and compile it, i'm guessing my screen will have

enter the...

enter the...

enter the...

then the teacher plugs in numbers and solves the problems

But on the formula given, it doesn't include all width of the ship. should i put all this variable like the width in my program still?

When my teacher tests each program: he's going to have a set of numbers and he going to type in this number and press enter and it's going to tell him the distance.

so how would i do this. please help. I don't want to fail this class.