[cs23021] Re: Question about Project 3

Mikhail Nesterenko mikhail at cs.kent.edu
Sun Oct 8 22:41:44 EDT 2006


You can can assume that the user always inputs dollar and cent amounts.
Even if there are zero cents. That is: 1.00 

No complex input processing is required. Extraction operation should
be sufficient for this project.

> 
> Also, I do not understand why int rather than double is a better choice 
> for taking money as input? Does C++ handles dollar amount in a 
> different way from a floating point?


Regarding floating point numbers. The issue is their representation in
the computer. All numbers are represented by as fractions of 2. If 2
does not divide the number for example 1/3 then the number is
represented approximately. This representation produces unexpected
rounding errors. Thus, it is not a good idea to do integer arithmetic
with floating point numbers. You will learn more about this in your
computer architecture class.

> 
> > 
> > > If the variables in the program are all int variables, then I do not 
> > > understand how to store the "decimal" amount of money deposited by the 
> > > user ( for example, 1.50) into an "integer" variable.
> > > 
> > 
> > There are multiple ways of doing it. One way, which would save on
> > computations, would be to store and process the money amounts in cents
> > converting to cents and dollars (with integer division and remainder
> > operation) only for input and output. That is $1.50 would be 150
> > cents.





More information about the cs23021 mailing list