Line: 1 to 1  

 
Changed:  
< <  Due: Oct 3, 11:55pm  
> >  Due: Feb 22, 11:55pm  
Changed:  
< <  Moodle Link  
> >  Moodle Link  
Instructions
Grading Table
Problem 1  Change ComputationThis is a very simple program. It is merely a main function that calls the computeCoin function. The trick is that you MUST follow a "specification" (given below) to write the computeCoin function to work exactly as the the comments in the declaration below specify. The learning goals here are:
Write a program that tells what coins to give out for any amount of change from 1 cent to 99 cents. For example, if the amount is 86 cents, the output would be something like the following: 86 cents can be given as 3 quarter(s) 1 dime(s) and 1 penny(pennies) Use coin denominations of 25 cents (quarters), 10 cents (dimes), and 1 cent (pennies). Do not use nickel and halfdollar coins. Your program will use a function that meets the following specifications. The idea is that you are being asked to write a specific function computeCoins, that is a general purpose function that when given a coin value coinValue (25, 10, or 1 in this case), and an amount of change remaining amountLeft, will return the quantity of that coin that should be given as change in the calbyreference parameter number, and will update the amount left in the callbyreference parameter amountLeft to be the amount left AFTER subtracting the number * coinValue quantity from the amountLeft.
< SyntaxHighlightingPlugin > void computeCoins(int coinValue, int& number, int& amountLeft); //Precondition: 0 < coinValue < 100; 0 <= amountLeft < 100. //(CoinValue will always be 25, 10, or 1 for this project) //Postcondition: number has been set equal to the maximum number of coins of //denomination coinValue cents that can be obtained from amountLeft //amountLeft has been decreased by the value of the coins to be returned, that is, //amountLeft is decreased by number*coinValue. < end SyntaxHighlightingPlugin >
For example, suppose the value of the variable amountLeft is 86 . Then, after the following call, the value of number will be 3 (for 3 quaters) and the value of amountLeft will be 11 (because when you take 3 quarters from 86 cents, this leaves 11 cents):
< SyntaxHighlightingPlugin > amountLeft = 37; computeCoins(25, number, amountLeft); cout << "Quarters to return:" << number << " with " << amountLeft << "cents remaining." << endl; < end SyntaxHighlightingPlugin > The above sample code would return:  
Deleted:  
< <  
Quarters to return: 1 with 12 cents remaining. So  once you have written the function computeCoins, you will write a main program that uses computeCoins to figure out the change for an given amount entered by the user. It will need to call computerCoins several times to do this correctly. Note that computeCoins will NOT do any input or output (e.g. cin or cout). This will all be done in the main program. Include a loop in your program that lets the user repeat this computation for new input values until the user says he or she wants to end the program. Hint
Sample runsEnter the amount of money between 1 and 99 cents: 62 Quarters: 2 Dimes: 1 Pennies: 2 go again? (y to continue):y Enter the amount of money between 1 and 99 cents: 23 Quarters: 0 Dimes: 2 Pennies: 3 go again? (y to continue):y Enter the amount of money between 1 and 99 cents: 133 Amount must be between 1 and 99 cents Enter the amount of money between 1 and 99 cents: 45 Quarters: 1 Dimes: 2 Pennies: 0 go again? (y to continue):n Turn in Runs for:
