CSCI 1300, Section 100
Hints on Assignment 1

LAST MODIFIED ON 9/14/03 12:30 a.m.

1. Before you even think about writing a program, think about the way that you would solve this problem.  Start with part 1 of the assignment.  If someone asked you to make change for $1.45, how would you do it?  How do you determine the number of dollars?  How do you then go on and determine the number of quarters?  Etc.  Work through a few problems by hand and you will understand the algorithm -- the sequence of steps -- you use to solve the problem.

2. The user's input must be real-valued (i.e., a "double" variable).  However, you will find it much easier to do this assignment if you convert this input -- which is in dollars -- to an integer value in pennies, and if you work with the number of pennies to be returned for the rest of the program.  (I pretty much said this in the assignment, but I just want to be unambiguous.)  Remember that when you convert from a double to an int you should worry about rounding.  Your code will look something like this:
double change_in_dollars;
int change_in_pennies;

// first read an amount to produce in change into the variable change_in_dollars

// now convert to units of pennies
change_in_pennies = change_in_dollars * 100. + .5;

// the rest of your program should operate on change_in_pennies
3. If you do not know where to begin coding, go back and look at the long multiplication program we did in class that prints out the long multiplication of two three digit numbers.  Make sure you completely understand that program.   To solve that problem, we had to extract the 100's digit of a three-digit number (e.g., 4 is the 100's digit of 456).  The 100's digit is nothing more than the number of times that 100 goes into the three-digit number.  The problem of determining the number of 100's in 456 is identical to the problem of determining the number of dollars in 456 pennies.

4. Another example that will help you in class is the egg inventory program, which keeps track of the number of eggs remaining in the refridgerator.  The number of eggs remaining is a lot like the amount of money remaining to be given back in chage.  For example, if you owe 247 cents in change and you give out 2 dollars, you have 47 cents remaining to be given in change.

5. Do part 1 before you worry about parts 2 and 3.  If you hand in only part 1, you can get a maximum of 60 of 100 points; if you hand in only parts 1 and 2, you can get a maximum of 80 of 100 points.

6. Start with just the problem of printing out the number of dollars that should be produced in change.   Handling dollars, quarters, dimes, nickels, and pennies is all pretty much the same code, so once you've figured out how to do one denomination, the other denominations should involve essentially the same code.  Your program may get long, but the length comes from repeating the snippet of code you wrote for one denomination for each different denomination.

7. You may assume that the user input (the amount of money to be changed) is valid.  You do not have to do error checking for legal dollar amounts (e.g., you can assume that the amount is nonnegative, and that you have sufficient cash in the register to produce change).

8.  The assignment is not completely clear:  The user should be asked how much $ is to be given in change.  You do not have to ask the user for the total sale amount and the amount tendered, and then subtract one from the other to get the amount of $ to be given in change.  The sample output (in the typewriter font) is supposed to represent a typical run from your program.

9. We did not specify how many of each denomination must be in the register for Part 3.  You can pick numbers.  But be sure you test your program thoroughly:  You should verify that if, say, you have only 2 quarters in the register and the change called for is 78 cents, your program will return the correct total change.  Perform a similar check for each denomination in the register.

10. When you compile your program, you will get warning messages if you store a double value in an integer variable.  You can ignore these warnings, or you can force a double expression to an int using the int(...) function, e.g.,

double x;
int i;

...

i = int(x);   // instead of i = x;