Lab 2 : Exact Change
June 22, 2020
Instructions:
The second lab will cover branching and conditions. Log in to your Zybooks account. If you haven't already signed up in zyBooks, see the course syllabus on how to do this. Open the second lab, found in section 3.25. Edit and run your program in "Develop Mode", and then switch to "Submit Mode" when you want to run the official tests.
What you will Need to Do::
This is a coin exchange problem. Given an integer input, write a program that outputs the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. For 0 or negative input, output "No change".
Examples:
Input: 178
output:
Steps to follow:
Check the attached file for more details.
The second lab will cover branching and conditions. Log in to your Zybooks account. If you haven't already signed up in zyBooks, see the course syllabus on how to do this. Open the second lab, found in section 3.25. Edit and run your program in "Develop Mode", and then switch to "Submit Mode" when you want to run the official tests.
What you will Need to Do::
This is a coin exchange problem. Given an integer input, write a program that outputs the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. For 0 or negative input, output "No change".
Examples:
Input: 178
output:
1 Dollar 3 Quarters 3 Pennies
Steps to follow:
- Declare proper variables. You will need at least 6 variables, 1 for input, and 5 for various coin types.
- Read the input value
- Verify your input is not zero or negative, if it is, output the appropriate message
- Calculating how many coins each type has
- Pick the largest denomination that is not greater than the remaining amount.
- Calculate number of coins for that coin type by dividing the remaining amount by the value of the coin type. ( example: numberOfQuarters = value/25 )
- Update the remaining value
- Go to the next biggest denomination and repeat the steps above
- Once the number of each coin type is determined start printing by using multiple if and if-else statements
Check the attached file for more details.