Pseudo code for lab 3 – the change calculator program
To determine the steps necessary to solve the problem I usually use real numbers and solve it manually first and keep track of the steps it took to solve the problem. I have included the “real” numbers in blue. They are NOT part of the pseudo code. It is my attempt to show you what I am thinking as I go through the problem solving process.
|
Step |
Variable Needed |
Data Type |
|
Get the Total Due from the user and store in numeric variable (Floating Point) Imagine $7.26 |
Total Due |
Floating Point |
|
Get the Amount Paid form the user and store in a numeric variable (Floating Point) Imagine $10 |
Amount Paid |
Floating Point |
|
Calculate Change Due by Subtracting Total Due from Amount Paid, store result in numeric variable (Floating Point) 2.74 |
Change Due |
Floating Point |
|
Calculate the Amount of Change in Cents by multiplying Change Due by 100, store result in a numeric variable (integer). 274 |
Amount of Change in Cents |
Integer capable of holding a very large number. $35 * 100 = 35,000 |
|
Determine the Number Of Dollars by dividing the Amount of Change in Cents (274) by 100 and ignoring the remainder, store result in integer variable. 2 |
Number of Dollars |
Integer |
|
Determine the Amount of Change in Cents remaining by dividing Amount of Change in Cents (274) by 100 and storing the remainder back in Amount of Change in Cents. 74 |
|
|
|
Determine the Number Of Quarters by dividing the Amount of Change in Cents (74) by 25 and ignoring the remainder, store result in integer variable. 2 |
Number of Quarters |
Integer |
|
Determine the Amount of Change in Cents remaining by dividing Amount of Change (74) in Cents by 25 and storing the remainder back in Number of Cents. 24 |
|
|
|
Determine the Number Of Dimes by dividing the Amount of Change in Cents (24) by 10 and ignoring the remainder, store result in integer variable 2 |
Number of Dimes |
Integer |
|
Determine the Amount of Change in Cents remaining by dividing Amount of Change (24) in Cents by 10 and storing the remainder back in Number of Cents. 4 |
|
|
|
Determine the Number Of Nickels by dividing Amount of Change in Cents (4) by 5 and ignoring the remainder, store result in integer variable 0 |
Number of Nickels |
Integer |
|
Determine the Amount of Change in Cents remaining by dividing Amount of Change (4) in Cents by 5 and storing the remainder back in Number of Cents. 4 This is the number of pennies |
|
|
|
Display the Change Due (2.74), formatted in the appropriate label Display the Number of Dollars (2) in the appropriate label Display the Number of Quarters (2) in the appropriate label Display the Number of Dimes (2) in the appropriate label Display the Number of Nickels (0) in the appropriate label Display the Amount of Change in Cents (4) in the appropriate label |
|
|