subject

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 half-dollar coins. your program will use the

following function (possibly among others):

void computecoin( int coinvalue, int& number, int& amountleft );

// precondition: 0
// postcondition: number has been set equal to the maximum

// number of coings of denomination coinvalue cents that

// can be obtained from amountleft cents. amountleft has

// been decreased by the value of the coins, that is,

// decreased by number*coinvalue.

for example, suppose the value of the variable amountleftis 86. then, after the

following call, the value of numberwill be 3 and the value of amountleftwill be 11

(because if you take three quarters from 86 cents, that leaves 11 cents):

computecoins(25, number, amountleft);

testing your program:

be sure to test your program with various values to ensure it provides the correct

output before submitting to get full credit. for extra credit, have your program only

accept proper input values (1 to 99). if the user attempts to enter an invalid

number, your program should output an error message and repeat the input

process until it receives an appropriate value. (hint: use a while or do-while loop.)

could you edit and improvise on this code to work :

#include "stdafx. h"
#include
#include
using namespace std;

void computecoin(int coinvalue, int& number, int& amountleft)

{
number = amountleft/ coinvalue;
amountleft = amountleft - (coinvalue*number);
}

int amount = 0;
int number = 0;
int quarters = 0;
int dimes = 0;
int pennies = 0;
int change = 0;

int main()
{
cout < < " enter the amount desired: " ;
cin> > amount;

do
{
if( amount < 1 || amount > 99)
cout < < " error, enter value between 1 and 99 cents.\n";
}
while( amount > 1 || amount < 99 );
{
amount = change;
amount++;

if (amount < 100 & & amount > = 25)
{
change = amount/25;
quarters++;
}
else if (amount < 25 & & amount > = 10)
{
change = amount/10;
dimes++;
}
else if (amount < 10 & & amount > =0)
{
change = amount/1;
pennies++;
}

computecoin (25, quarters, amount);
cout < < amount < < " " < < number < computecoin (10, dimes, amount);
cout < < amount < < " " < < number <
computecoin (01, pennies, amount);
cout < < amount < < " " < < number < cout< < " the change desired is: " < < change;

}

return (0);

}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 12:30
What characteristic of long period comets suggest they come directly from the oort cloud?
Answers: 2
question
Computers and Technology, 22.06.2019 18:30
Kto rozmawia z clamentain przez krótkofalówke w the walking dead która śledzi lee w 4 epizodzie
Answers: 1
question
Computers and Technology, 22.06.2019 19:20
Consider the following code snippet: #ifndef cashregister_h#define cashregister_hconst double max_balance = 6000000.0; class cashregister{public: cashregister(); cashregister(double new_balance); void set_balance(double new_balance); double get_balance() const; private: double balance[12]; }; double get_monthly_balance(cashregister bk, int month); #endifwhich of the following is correct? a)the header file is correct as given.b)the definition of max_balance should be removed since header files should not contain constants.c)the definition of cashregister should be removed since header files should not contain class definitions.d)the body of the get_monthly_balance function should be added to the header file.
Answers: 1
question
Computers and Technology, 23.06.2019 00:00
What engine component is shown in the above figure?
Answers: 1
You know the right answer?
Write a program that tells what coins to give out for any amount of change from 1

cent...
Questions
question
Mathematics, 20.11.2019 21:31
Questions on the website: 13722361