Go to Post if your robot weighs 1-1/2 tons, you have bigger problems then the legality of that jack... - ekapalka [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
programming help needed krunal Programming 3 29-01-2007 00:18
Help on a Homework Assignment. Pavan Dave General Forum 1 13-09-2006 14:20
HELP-URGENT PROGRAMMING HELP NEEDED Rohith Surampudi Lego Mindstorm Discussion 1 24-03-2006 23:05
URgent Programming Help needed rcubes85 Programming 4 15-02-2005 23:21


All times are GMT -5. The time now is 09:30.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi