Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Converting Data EasyC (http://www.chiefdelphi.com/forums/showthread.php?t=61636)

charlie1218 14-01-2008 10:27

Converting Data EasyC
 
Hi all,

For a project I am doing seperate from FRC, i am making a mini darpa rover. The question i have is, how do i take a deg,min,sec value (ex. 172*34'53") and convert into decimals in programming. By hand it should be 172 + (34/60) + (53/3600). But alas I cant do that so easily in EasyC. Any suggestions?:confused:

Gamer930 14-01-2008 13:57

Re: Converting Data EasyC
 
Put this into a user code block
answer = 172 + (34/60.0) + (53/3600.0);

When you do .0 it does Decimal Division instead of integer division

34/60 in integer division is 0 so you were doing 172 + 0 + 0

Alan Anderson 14-01-2008 15:45

Re: Converting Data EasyC
 
You could also save the CPU a tiny bit of computational exertion by turning minutes into seconds first, adding the seconds, then converting the result to fractional degrees when you add things up at the end.

34*60 + 53 = 2093

172 + 2093/3600.0 = 172.581

charlie1218 15-01-2008 20:47

Re: Converting Data EasyC
 
but i wont know the value to begin with. it will come to me in the form of x*y'z" but the number could be anything

Gamer930 15-01-2008 21:48

Re: Converting Data EasyC
 
Is that going to be given to you as 3 separate variable?? Then you can just insert those variables into the formula. answer = Variable1 + (Variable2/60.0) + (Variable3/3600.0);

If you are given a string in that exact format then you would have to use a "Tokenizer and Tokens" not sure how you would do that in C or EasyC. If you would like how to do it in C++ send me an e-mail and I will send you some sample code.


All times are GMT -5. The time now is 01:48.

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