View Single Post
  #1   Spotlight this post!  
Unread 18-05-2007, 23:51
Pat McCarthy Pat McCarthy is offline
FiM Volunteer
FRC #0067 (HOT Team)
Team Role: Alumni
 
Join Date: May 2003
Rookie Year: 2003
Location: Grand Rapids, MI
Posts: 593
Pat McCarthy has a reputation beyond reputePat McCarthy has a reputation beyond reputePat McCarthy has a reputation beyond reputePat McCarthy has a reputation beyond reputePat McCarthy has a reputation beyond reputePat McCarthy has a reputation beyond reputePat McCarthy has a reputation beyond reputePat McCarthy has a reputation beyond reputePat McCarthy has a reputation beyond reputePat McCarthy has a reputation beyond reputePat McCarthy has a reputation beyond repute
Send a message via AIM to Pat McCarthy
C Programming Homework Help Needed

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",&degree);

printf("%f degrees\n", &degree);

	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!
Attached Thumbnails
Click image for larger version

Name:	NaN.jpg
Views:	212
Size:	43.5 KB
ID:	5539  
__________________
2003-2006: FRC Team 67 - Drafter, Driver, Student Leader
2006 Volunteering: Kettering Kickoff Ref, Team Ford FIRST Robotics Invitational Ref
2007 Volunteering: GLR Field Reset/Repair; WMR Robot Inspector and Scorekeeper; MARC Referee
2008 Volunteering: WMR Planning Committee, WMR Scorekeeper, MARC Ref, IRI Scorekeeping, WMRI Scorekeeping & DJ
2009 Volunteering: Kettering District, MARC, IRI, and WMRI Scorekeeper/Field Power Controller
2010 Volunteering: Kettering District, MARC, IRI, and WMRI Scorekeeper/Field Power Controller
2011 Volunteering: Waterford District, West Michigan District, MARC, & IRI DJ
2012 Volunteering: Waterford District, West Michigan District DJ