Hi all,
I'm taking an course, "Structured Programming in C" and am having some issues with my homework for the week.
My assignment is to write a program that calculates various aspects of projectile motion, but I am running into a problem with an output(?) in my program.
When I compile the program I receive no errors or warnings, but when I try to enter values into the first input, it turns the value into '+NAN'. I don't know what '+NAN' is or how to fix it.
I've attached a screen capture of what happens when the program is run and values are entered.
HELP!
Please excuse the messiness of the code, as it is not completed or functional.
Code:
/*
* Author: Patrick McCarthy
* Filename: P34.c
* Description: Homework 2, Chapter 3:4, CS261
* This program computes the duration of a projectile's flight
* and its height above the ground when it reaches the target.
*/
#include <stdio.h>
#include <math.h>
/* Function prototype */
float find_radians(float theta);
/* Function prototype */
float calculate_time(float distance, float velocity, float theta);
/* Function prototype */
float calculate_height(float velocity, float theta, float time);
int main(void)
{
float degree;
float theta;
float distance;
float velocity;
float time;
float height;
/* Gets the angle of elevation from the user */
printf("Enter angle (in degrees) of elevation =>");
scanf("%f",°ree);
printf("%f degrees\n", °ree);
theta = find_radians(degree);
printf("%f radians\n", &theta);
/* Gets the distance to the target from the user */
printf("Enter distance (in feet) to target =>");
scanf("%f" ,&distance);
/* Gets the projectile's velocity from the user */
printf("Enter projectile's velocity (ft/sec) =>");
scanf("%f", &velocity);
calculate_time(distance,velocity,theta);
/* Displays time of projectile flight to user */
printf("Time of flight is %f seconds.\n", &time);
calculate_height(velocity,theta,time);
/* Displays height of projectile at impact to user */
printf("Height of projectile impact is %f feet from the ground.\n", &height);
return 0;
}
/* Converts degrees to radians */
float find_radians(float degree)
{
float theta; /* local variable */
float Pi = 3.14159;
theta = degree * (180/Pi);
return (theta);
}
float calculate_time(float distance,float velocity,float theta)
{
float time; // local variable
time = distance / ( velocity * cos(theta) );
return (time);
}
float calculate_height(float velocity, float theta, float time)
{
float height; // local variable
float g = 32.17; // Declares acceleration due to gravity as -32 ft/s/s
height = velocity * sin(theta) * time - ( (g * time*time) / 2 );
return (height);
}
Thanks!