Computers and Technology

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);

}

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 23:30, jcollings44
You picked the corridor which led you here. if the guards find you, they're going to be really angry! what is the synonym of angry
Answers: 1
image
Computers and Technology, 22.06.2019 08:10, autumnguidry1622
Technician a says that if a valve is open when a piston rises to the very top of a cylinder, the piston may actually strike the valve head and cause serious engine damage. technician b says if the camshaft is located in the engine block, then the engine is called an overhead valve engine, ohv engine, or an in-block camshaft. who is right? a. b only b. both a and b c. a only d. neither a nor b
Answers: 3
image
Computers and Technology, 23.06.2019 19:50, Aprillove7939
Which feature is selected to practice and save the timing of a presentation
Answers: 1
image
Computers and Technology, 24.06.2019 03:00, greenhappypiggies
Using a conditional expression, write a statement that increments numusers if updatedirection is 1, otherwise decrements numusers. ex: if numusers is 8 and updatedirection is 1, numusers becomes 9; if updatedirection is 0, numusers becomes 7.
Answers: 1
Do you know the correct answer?
Write a program that tells what coins to give out for any amount of change from 1

cent...

Questions in other subjects: