Tuesday, August 9, 2011

Chapter 3, exercise 1

1.  In what variable type would you best store the following values?


a.  A person's age to the nearest year.

unsigned char

b.  A person's weight in pounds.

unsigned short

c.  The radius of a circle.

float

d.  Your annual salary.

float, or if I am not earning very large amounts of money or if I ignore cents or express the total amount in cents rather than dollars, unsigned long

e.  The cost of an item.

float, or if the item is not very precious, or if I ignore cents or express the total amount in cents rather than dollars, unsigned long

f.  The highest grade on a test (assume it is always 100).

unsigned char

g.  The temperature.

float

h.  A person's net worth.

float or assuming the person is not rich and I am happy to express the value in cents, unsigned long

i.  The distance to a star in miles.

float

No comments:

Post a Comment