## 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

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

Xanthir
My HERO!!!
Posts: 5400
Joined: Tue Feb 20, 2007 12:49 am UTC
Contact:

### Re: Declaration of value

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)))

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

### Re: Declaration of value

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.

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

### Re: Declaration of value

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.

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

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

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.