Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Implement the following code in C, thank you. been having difficulty with it Problem Background Create a program to process cash change using standard U.S.
Implement the following code in C, thank you. been having difficulty with it
Problem Background Create a program to process cash change using standard U.S. denominations of pennies, nickels, dimes, quarters, dollar bills, five-dollar bills, tens, and twenties. Figure out how many of each bill or coin that you expect to get back for a given amount. For example, if you need to give back $3.87 in change, you would have 3 one-dollar bills 3 quarters 1 dime 2 pennies What is the algorithm you need to accomplish this? Analyze the problem and design the algorithm first, and then think about the functions you need to make it work. You should be able to do this first part without using any IF statements. If you're using IFs here, you're doing it incorrectly. Computing the change is just a matter of subtraction and multiplication. Write this out and desk check it before you start to program. It will make writing the program easier. The Fun Twist! Sometimes, you don't have all the denominations available in your cash drawer - a shortage of one of the denominations! Write your program to allow for being out of a denomination or multiple denominations: dimes, for example. In that case, the $3.87 ends up being 3 ones, 3 quarters, 2 nickels and 2 pennies. TWO DOLLARS TWO DOMAIN A96476998 A A A96476998 720 WASHINGTON DC LECTOR UNITED STATES OFAMERICA WODOLARS Again, think about the algorithm you need to accomplish this before you start to code. 4. First, write your program to handle the situation where there is no shortage, and you have all the coins and bills available. Create a function to prompt the user to enter an amount. This function should be named prompt_user_for_amount(). 5. Create another function called calculate change ( ), which takes one input parameter, the amount of money needed to give back, and then one output parameter for each of the eight denominations, giving 9 parameters in total. 6. Next, write a function to print the results, print_change ( ), with the eight denominations as parameters. 7. Validate your program works by running it and scripting with the following amounts: a) b) c) d) e) 116.23 5.99 0.32 278.92 52.00 IN GOD WE TRUST S 0 8. Copy your source code to a new file to modify, keeping the working first part separate. lab4.c lab4_with_shortages.c 9. Create a function to prompt the user to ask for shortages, after the user enters the amount. This should be a separate function, called prompt_for_shortages ( ), that takes a string to use for a prompt and returns the one that's missing, using the symbolic constants below. The prototype should look like the following: int prompt_for_shortages( char *prompt ); You will need to invoke this function three times, giving the user an opportunity to identify up to three denominations as missing. 10. We will use the following codes to represent the various denominations in the program, and these codes are what the function prompt_for_shortages ( ) will return. If there are no missing denominations, all three of these return parameters will be NO_MISSING. #define NOTHING MISSING #define NO PENNIES #define NO NICKELS #define NO DIMES #define NO QUARTERS #define NO DOLLARS #define NO FIVES #define NO TENS #define NO TWENTIES 0 1 2 3 4 5 6 7 8 11. Now you can add IF statements to the program, to check to see if any given denominations are missing 12. To make sure your program is working correctly, create a script of the output using the same values from the first part above, but this time, eliminate a) dollars and dimes b) fives, dimes, and nickels c) twenties and penniesStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started