Go to Post Viva La FIRST Revolucion! - phrontist [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

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #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:	213
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
  #2   Spotlight this post!  
Unread 19-05-2007, 00:05
Joel J's Avatar
Joel J Joel J is offline
do you..
no team
 
Join Date: May 2001
Rookie Year: 2000
Location: San Jose, CA
Posts: 1,445
Joel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond repute
Re: C Programming Homework Help Needed

As one step, you can remove the & sign from your printf statements.

For example,

printf("Time of flight is %f seconds.\n", &time);

becomes:

printf("Time of flight is %f seconds.\n", time);
__________________
Joel Johnson

Division By Zero (229) Alumni, 2003-2007
RAGE (173) Alumni, 1999-2003
  #3   Spotlight this post!  
Unread 19-05-2007, 00:32
Flash Flash is offline
Registered User
None #1151
Team Role: Engineer
 
Join Date: May 2007
Rookie Year: 2007
Location: Rochester
Posts: 1
Flash is on a distinguished road
Re: C Programming Homework Help Needed

Joel is correct. Remove the & from your printf functions. The & means "address of". Printf doesn't want the address of the location where the number is kept, printf wants the number itself.

FYI, the & is correct in the scanf function. Scanf requires the address of the variable.

Btw NAN means "Not A Number".

Flash.
  #4   Spotlight this post!  
Unread 19-05-2007, 01:09
EricVanWyk EricVanWyk is offline
Registered User
no team
 
Join Date: Jan 2007
Rookie Year: 2000
Location: Boston
Posts: 1,597
EricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond repute
Send a message via AIM to EricVanWyk
Re: C Programming Homework Help Needed

I'm a bit confused as to exactly how this code compiled, and why it isn't happy. I know exactly enough C to confuse myself.

I understand why the code is wrong. I don't fully understand why this is the error that is given.

Since printf takes a variable number of untyped objects, I'll believe that it can't catch the type mismatch of address and float. This must be the case, since it did compile. Since C has no run-time environment to speak of, we must assume that the computer will do exactly what it is told: Take the address and interpret it as a float.

The code then loosely translates to:
Code:
float time;
int * backdoor = &time;
*backdoor = "integer value of the address of the variable time"
print time;
At this point we essentially have "take a random bit string and interpret it as a float". Why is this float NaN? I know that the float space does have NaN gaps, but I thought the space was relatively dense. In otherwords, I thought it was so dense that the probability of this error should be rather small. Does it happen repeatably? Is there something about the addressing space that places variables in the realm of NaN?

I may be reading too far into this, but I'd really appreciate the assistance of someone with a deeper understanding of C.

Thanks
Eric
  #5   Spotlight this post!  
Unread 19-05-2007, 08:54
Bongle's Avatar
Bongle Bongle is offline
Registered User
FRC #2702 (REBotics)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Waterloo
Posts: 1,069
Bongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond repute
Send a message via MSN to Bongle
Re: C Programming Homework Help Needed

I just ran it in Code::Blocks (open-source IDE, it is quite good), and no matter what number I entered, I got 0.0000 degrees, 0.00000 radians.

Check the scanf documentation, there is probably something small you're doing wrong.
Edit: I read the scanf documentation, and there doesn't appear to be anything wrong. Good luck.

Last edited by Bongle : 19-05-2007 at 09:02.
  #6   Spotlight this post!  
Unread 19-05-2007, 11:30
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
Re: C Programming Homework Help Needed

Quote:
Originally Posted by Joel J. View Post
As one step, you can remove the & sign from your printf statements.

For example,

printf("Time of flight is %f seconds.\n", &time);

becomes:

printf("Time of flight is %f seconds.\n", time);
Thanks Joel, that did it.

To answer another question, I'm using the Borland C 5.5 compiler.
Attached Thumbnails
Click image for larger version

Name:	Program.jpg
Views:	164
Size:	95.1 KB
ID:	5548  
__________________
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
  #7   Spotlight this post!  
Unread 09-06-2007, 18:22
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
Re: C Programming Homework Help Needed

Back again...

I'm only concerned with a small portion of my program at the moment.
This part collects an integer value for use to set the color of an object later in the program, then checks to make sure it is within a certain range of numbers. If the number isn't within that set of numbers, it is supposed to ask the user to enter again, then collects a value again.

Currently, whether the value entered is within the parameters that I want, this chunk of program gets stuck in the error checking loop. Oddly, when you enter a two digit integer, it breaks the loop.

Code:
	/* Collects shape selection from user and checks for invalid inputs */
	do
	{
		color_error = 0;
		
		/* Collects desired color from user */
		printf("\nSelect color:\n");
		printf("BLACK (0), BLUE (1), GREEN (2)\n");
		printf("CYAN (3), RED (4), MAGENTA (5)\n=>");
		fflush(stdin);
		scanf("%d", &color);
		printf("Selected color: %d\n", color);
		fflush(stdin);

		/* Valitdate entry */
		switch (color)
		{
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
				break;
				
			default:
				color_error = 1;
				printf("Please select one of the available colors\n");
				break;
		}
	}
	while(color_error);
I've attached an image of what happens when the code is executed and the entire program's code. It needs to be compiled with a special .lib file that my prof wrote. (something in the forums is keeping me from attaching it)
Attached Thumbnails
Click image for larger version

Name:	Color_input.jpg
Views:	111
Size:	46.5 KB
ID:	5582  
Attached Files
File Type: c shape.c (2.1 KB, 89 views)
__________________
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

Last edited by Pat McCarthy : 09-06-2007 at 18:29.
  #8   Spotlight this post!  
Unread 09-06-2007, 18:56
Mike Bortfeldt Mike Bortfeldt is offline
Registered User
FRC #1126 (& 1511)
Team Role: Mentor
 
Join Date: Oct 2004
Rookie Year: 2004
Location: Rochester, NY
Posts: 119
Mike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud of
Re: C Programming Homework Help Needed

Pat,

It looks like you are not being consistant with the data type for "color". You are inputting it as an integer (%d) so I'll assume you've defined it as such, however you are comparing it in the switch statement as a character. The value '0' will be converted to it's ASCII value (48) for the compare. If 'color' is an integer, then I'd try removing the single quotes from around the numbers in the case statements and see if that works.

Mike
  #9   Spotlight this post!  
Unread 09-06-2007, 19:22
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
Re: C Programming Homework Help Needed

Quote:
Originally Posted by Mike Bortfeldt View Post
Pat,

It looks like you are not being consistant with the data type for "color". You are inputting it as an integer (%d) so I'll assume you've defined it as such, however you are comparing it in the switch statement as a character. The value '0' will be converted to it's ASCII value (48) for the compare. If 'color' is an integer, then I'd try removing the single quotes from around the numbers in the case statements and see if that works.

Mike
Thanks, that did it. I didn't realize that single quotes changed things.
__________________
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
  #10   Spotlight this post!  
Unread 10-06-2007, 14:42
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
Re: C Programming Homework Help Needed

I think I need to make this the "Help Pat pass EGR 261" thread.

My problem this time is that a switch statement again.
After the menu displays, the user can enter a selection, but when they hit enter, it just displays a blank line and doesn't leave the switch statement.

Thanks for the continuing help guys.

Code:
	int menu_error;
	int menu_selection;

	do
	{
		do
		{
			menu_error = 0;
		
			/* Displays main menu */
			printf("Please select from the following options:\n");
			printf("(1) Draw a colored shape\n");
			printf("(2) Clear graphics window\n");
			printf("(3) Exit\n=>");
			fflush(stdin);
			scanf("%d\n", &menu_selection);

			switch(menu_selection)
			{
				case 1:
					draw_shape();
					break;
					
				case 2:
					clear_graphics();
					break;

				case 3:
					break;

				default:
					menu_error = 1;
					printf("Please enter a selection 1, 2, or 3");
			}
		}
		while(menu_error);
	}
	while(menu_selection != 3);
__________________
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
  #11   Spotlight this post!  
Unread 10-06-2007, 15:55
Mike Bortfeldt Mike Bortfeldt is offline
Registered User
FRC #1126 (& 1511)
Team Role: Mentor
 
Join Date: Oct 2004
Rookie Year: 2004
Location: Rochester, NY
Posts: 119
Mike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud of
Re: C Programming Homework Help Needed

Pat,

I'm not sure the problem is in the switch statement. Try removing the \n from the menu_selection scanf line ("%d" rather than "%d\n")

Mike
  #12   Spotlight this post!  
Unread 10-06-2007, 17:42
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
Re: C Programming Homework Help Needed

Quote:
Originally Posted by Mike Bortfeldt View Post
Pat,

I'm not sure the problem is in the switch statement. Try removing the \n from the menu_selection scanf line ("%d" rather than "%d\n")

Mike
That was it! Thanks again!
__________________
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
  #13   Spotlight this post!  
Unread 01-07-2007, 14:39
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
Re: C Programming Homework Help Needed

Back again!
I can't figure out how to convert a float value to a char string.
Suggestions? Thanks!
__________________
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
  #14   Spotlight this post!  
Unread 01-07-2007, 15:19
bear24rw's Avatar
bear24rw bear24rw is offline
Team 11 Programming Captain
AKA: Max T
FRC #0011 (MORT)
Team Role: Programmer
 
Join Date: Sep 2005
Rookie Year: 2005
Location: Flanders, NJ
Posts: 385
bear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to behold
Send a message via AIM to bear24rw
Re: C Programming Homework Help Needed

Quote:
Originally Posted by Pat McCarthy View Post
Back again!
I can't figure out how to convert a float value to a char string.
Suggestions? Thanks!
Like take value 9.023 and turn it into '9' '.' '0' '2' '3' in a char string?

Idk how you would get each number individually but to change the number into its ASCII code you would do
# + '0' to get the ascii code of the number
  #15   Spotlight this post!  
Unread 01-07-2007, 15:21
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
Re: C Programming Homework Help Needed

Quote:
Originally Posted by bear24rw View Post
Like take value 9.023 and turn it into '9' '.' '0' '2' '3' in a char string?
Well, I have a float variable that I need to be able to display using WinBGI using the text function that only accepts char strings. So, I really don't know exactly.
__________________
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
Closed Thread


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 13:22.

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