[cs23021] on input in Project 4
Mikhail Nesterenko
mikhail at cs.kent.edu
Thu Oct 4 10:31:46 EDT 2007
CS 1 students,
Note that the user inputs the amount of money into the
vending machine as follows
33.22
Where 33 is the number of dollars and 22 is the number of cents.
First, you can assume that the user always inputs cents. Even
if there are zero. Thin this case the input is of the form
33.0
Since you were asked to manipulate integers only. The input becomes an
issue. There are two ways to handle it.
* Either input this number into a variable of type double and then
convert into integer (don't forget to convert the fractional part).
* There is also this way
int dollars, cents;
char dot;
cin >> dollars >> dot >> cents;
In this case, the input such as 33.22 will be correctly
assigned to integer variables.
thanks,
--
Mikhail
More information about the cs23021
mailing list