Imagine you have a piggy bank containing only pennies and
nickels. You want to determine the total worth in dollars and
cents. In this activity you will be exploring a program that solves
this problem. Write the answers to each question in your lab
1. Obtain the source code for the solution: evalcoins.c
2. Study the source code and complete the table below (in your
lab notebook) with the predicted output for each test case:
||How many pennies: 35
How many nickels: 25
||How many pennies: 25
How many nickels: 35
||How many pennies: 24
How many nickels: 35
3. Run the program three times and provide the input
data shown in the table above. Verify that the output is the
same as your predicted. >
2. Compile the source code. It should compile with no errors.
5. What happens when you enter a number greater than 100 for pennies?
6. What happens when you enter a negative number for pennies?7. What happens when you enter a floating point value for pennies, say 11.5?
8. Change the output so instead of simply reporting amount of dollars and change, the display gives an explanatory message, for example
Your collection is worth:
1 dollars and 87 cents
9. Change the output so the result is displayed the way most currency amounts are shown, with a dollar sign and a decimal point.
Your collection is worth $1.87
Does your program display the correct answer if the coin total is one dollar and five cents ($1.05)?
(Most probably your program doesn't give the correct output, because the book hasn't yet explained how to deal with this situation. So don't worry about it for now. You should be able to make it display "$1. 5").
10. Modify the program so that it also accepts dimes.
11. Demonstrate that the variable names chosen by the programmer can
be changed by replacing
every occurrence of "total" with "bank". The program
should compile and execute without errors.
12. What does the % operator do in the calculation of change? Can
you rewrite the formula so that it work correctly using only the four
operators? Change the statement to use your alternative
formula and run it with the test data above to verify it works the
13. Submit your completed source code using this handin command:
handin graderjd Lab02 evalcoins.c