Declaration of value

A place to discuss the science of computers and programs, from algorithms to computability.

Formal proofs preferred.

Moderators: phlip, Moderators General, Prelates

evinda
Posts: 32
Joined: Fri May 03, 2013 10:16 pm UTC

Declaration of value

Postby evinda » Sat May 25, 2013 3:11 pm UTC

Hi!!!I have a question...
I want to use the value "age" at a program I have to write in C....
How must the value "age" be declared????As INT or FLOAT???Thank you :)

User avatar
Xanthir
My HERO!!!
Posts: 5400
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Declaration of value

Postby Xanthir » Sun May 26, 2013 12:11 am UTC

Well, is it an integer or not?

(I recommend studying your class examples or book.)
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
amylizzle
Posts: 41
Joined: Sat Mar 02, 2013 10:02 pm UTC

Re: Declaration of value

Postby amylizzle » Wed May 29, 2013 11:08 pm UTC

Do you need it to store fractional values (eg. 7.5, 6.66, 3.126)? Then you need a float.
If not, and you only need it to store whole numbers (eg. 1, 23, 10509), then you need an integer.

Recommended reading: http://physinfo.ulb.ac.be/cit_courseware/datas/data1.htm

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Declaration of value

Postby EvanED » Thu May 30, 2013 12:03 am UTC

amylizzle wrote:Do you need it to store fractional values (eg. 7.5, 6.66, 3.126)? Then you need a float.
If not, and you only need it to store whole numbers (eg. 1, 23, 10509), then you need an integer.
Let me add a caveat:

Sometimes, when you think you need fractional values, you still need an integer. Money is the classic example of this: because of (im)precision issues with floating point numbers, monetary values should be stored as, e.g., an integral number of cents rather than a floating point number.

monroearnold
Posts: 1
Joined: Tue Jun 04, 2013 9:35 am UTC
Location: 3803 Wildwood Street Youngstown, OH 44503

Re: Declaration of value

Postby monroearnold » Tue Jun 04, 2013 10:24 am UTC

Depends on whether You wish to keep it in round figure(Use integer) or exactly with months and days(Use float).
Last edited by monroearnold on Thu Jun 06, 2013 9:21 am UTC, edited 1 time in total.

DeGuerre
Posts: 51
Joined: Mon Feb 04, 2008 6:41 am UTC

Re: Declaration of value

Postby DeGuerre » Thu Jun 06, 2013 4:48 am UTC

evinda wrote:I want to use the value "age" at a program I have to write in C....
How must the value "age" be declared????As INT or FLOAT???Thank you :)

As others have noted, it depends what you're doing with it.

However, I should note that real systems never store someone's age, because it changes every day. If you need the information, store date of birth (and deal with the inevitable time zone/calendar weirdnesses). But you may need age as an intermediate value. At that point, you decide what you actually want it for. If, for example, you want to know if someone is old enough to vote, the law specifies an integer.


Return to “Computer Science”

Who is online

Users browsing this forum: No registered users and 7 guests