Question: Write a computer program that computes the duration of a projectile's flight and its height above the ground when it reaches the target. As part

Write a computer program that computes the duration of a projectile's
flight and its height above the ground when it reaches the target. As
part of your solution, write and call a function that displays instruc-
tions to the program user.
Problem Constant
G =32.17// gravitational constant
Problem Inputs
float theta // input - angle (radians) of elevation
float distance // input - distance (ft) to target
float velocity // input - projectile velocity (ft/sec)
Problem Outputs
float time // output - time (see) of flight
float height // output - height at impact
Relevant Formulas
time= distance/(velocity * cos(theta))
g x time2
height =(velocity x sin(theta) x time )-{(g * time^2)/2}
Try your program on these data sets.
Inputs Data Set 1 Data Set 2
Angle of elevation 0.3 radian 0.71 radian
Velocity 800 ft/sec 1,600 ft/ sec
Distance to target 11,000 ft 78,670 ft
This is what I have and I am not sure why it is not working any help would be great.
#define _CRT_SECURE_NO_DEPRECATE
// Save default warning level (push to the stack)
#pragma warning(push)
// Disable Microsoft Visual C++ WARNING C6031- Return value ignored: 'scanf'
#pragma warning(disable: 6031)
// Compiler Includes
#include
#include
// Constants
//Gravitational constant
#define G 32.17
void displayInstructions(){
printf("This program computes the duration of a projectile flight and its height above the groumd when it reaches the target.
");
printf("Please provide the following information:
");
printf("1. Angle of elevation in radians.
");
printf("2. Distance to the target in feet.
");
printf("3. Projectile velocity in feet/second.
");
}
int main(void){
// Local Variables
double theta =0.0;
double time =0.0;
double velocity =0.0;
double height =0.0;
double distance =0.0;
// call display instructions function
displayInstructions();
// prompt and get angle of elevation in radians
printf("Enter the angle of elevation (in radians):
");
scanf("%1f", &theta);
if (theta <=0|| theta >1.57){
// prompt and get distance to the target
printf("
Enter the distance to the target (in ft):
");
scanf("%1f", &distance);
if (distance >0){
// prompt and get velocity
printf("
Enter the velocity (in ft/sec):
");
scanf("%1f", &velocity);
if (velocity >0){
// calculate time
time = distance /(velocity * cos(theta));
// calculate height
height =(velocity * sin(theta)* time)-((G * pow(time,1))/2);
if (height >=0){
printf("
Height =%.2lf feet
Time =%.2lf seconds
", height, time);
}
}
else{
printf("You have entered an invalid value for velocity.");
}
}
else {
printf("You have entered an invalid value for distance.");
}
}
else {
printf("You have entered an invalid theta value.");
}
return 0;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!