answersLogoWhite

0


Best Answer

Use a recursive function. Assume the denominations are placed in a vector of type double (highest denomination first):

// returns the highest denomination not greater than value

const double get_largest_denom (const double& value) {

const std::vector<double> denoms {100.0, 50.0, 20.0, 10.0, 5.0, 2.0, 1.0, 0.5, 0.2, 0.1, 0.05, 0.02, 0.01};

for (auto const i : denoms) if (*i <= value) return *i;

return 0.0; // rare case!

}

void print_amounts (double value) {

if (value<=0.0) return;

double denom {get_largest_denom (value); }

unsigned count {(unsigned) (value / denom)};

double subtotal {(double) count * denom};

std::cout << count << " x " << denom " = " << subtotal << std::endl;

print_amounts (value - subtotal);

}

int main (void) {

double value {};

std::cout << "Enter the amount (#.##): ";

std::cin >> &value;

print_amounts (value);

}

Example output:

Enter the amount (#.##): 1234.56

12 x 100.0 = 1200.0

3 x 10.0 = 30.0

4 x 1.0 = 4.0

1 x 0.5 = 0.5

1 x 0.05 = 0.05

1 x 0.01 = 0.01

User Avatar

Wiki User

6y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What will be if we Write a program in java to accept the amount of money to be withdrawn and find out the number of notes of each denomination to be given by the bank?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Using simple sentence with the word 'accept?

Accept means to take or receive something.Do you accept the charges made against you in this court today?You have a collect call from Mozambique, do you accept the charges?Press yes to accept this amount, or no to decline.I accept your point, but I still can't agree with you.


The max number of functions you have used in a c program?

There is no limit to the number of functions you can have in a program. The only practical limit is dependant upon the amount of memory you have available in order to load the compiled program, whether it has 4 functions or 4 trillion functions. If the program makes use of dynamic libraries, then the amount of available memory reduces accordingly.


How do you loop a program in python 3?

A program can be looped in Python by wrapping the entire program in a for or while loop. If you wish to loop the program a finite amount of times, it can be done like so (x = the amount of times you want it to loop, this can be a number or variable storing a number): for i in range(0,x): [code] If you wish to loop the program infinitely, you can use a simple while loop: while True: [code]


How do you write a java program in which the user will enter an amount of money as a decimal number and the program will compute how many pennies nickels dimes quarters ones fives tens twenties etc.?

Denomination values should be stored in an integer array where each value is in pennies. So $100 is 10000 pennies: const array&lt;int,10&gt; value = {10000, 5000, 2000, 500, 100, 50, 25, 10, 5, 1}; Create a parallel array with the actual denominations: const array&lt;string,10&gt; denomination = {"hundreds", "fifties", "twenties", "fives", "dollars", "half", "quarters", "dimes", "nickels", "cents"}; Start by multiplying the amount by 100 to determine the actual number of pennies. So $1.23 becomes 123 pennies. Store this value as an integer named pennies. Now work your way through the denominations in sequence: for (int index=0; index&lt;value.size() &amp;&amp; pennies; ++index) { int number=pennies/value[index]; if (number) cout&lt;&lt;number&lt;&lt;' '&lt;&lt;denomination[index]&lt;&lt;endl; pennies%=value[index]; }


What is a depopulation program?

A depopulation program is a method to reduce the overall amount of people, animals, or organisms living within a given area. It is typically done to prevent the overcrowding of animals which cannot directly limit their own breeding.

Related questions

Where can you withdraw 1000 from an ATM at one time?

The answer will depend on the currency unit. I do not belive that such an amount, in pounds Sterling, can be withdrawn at a time.The answer will depend on the currency unit. I do not belive that such an amount, in pounds Sterling, can be withdrawn at a time.The answer will depend on the currency unit. I do not belive that such an amount, in pounds Sterling, can be withdrawn at a time.The answer will depend on the currency unit. I do not belive that such an amount, in pounds Sterling, can be withdrawn at a time.


What is the minimum amount of cash that can be withdrawn?

1 dollar (in u.s. money)


How much money can be withdrawn from a reverse mortgage from RBS?

The amount of money that can be withdrawn from a reverse mortgage from RBS depends on the age of the youngest borrower, the current interest rate, the MIP option you choose and the lesser amount of the appraisal.


What is The amount of the traveler's check such as 10 or 20?

denomination information


Is there Pension provision on PPF investment?

No. The amount accumulated can be withdrawn at maturity. Thats all


How much amount can be withdrawn from Federal bank ATM in a day as you have visa card?

haloo


What is the maximum amount of cash that can be withdrawn from an ATM at a?

it depend on your debit card balance in then time


What is the maximum amount of cash that can be withdrawn from an ATM at a time?

It depends on the limit placed on your debit card.


What will be employee provident account status if leaves his job and does not withdraw his amount for more than 4 years?

The amount can be withdrawn by appropriate forms duly


What is the maximum amount of money that can be withdrawn in one day?

Different banks and different accounts have different limits.


What is the largest Malaysian ringgit note denomination?

Currently RM100. There used to be 500 &amp; 1000 notes but they were withdrawn because people were taking large amounts out of the country during the Asian monetary crisis of 1999. There was a limit of RM1000 placed on the amount you could take out of the country at that time. See the related link for a detailed Wikipedia article.


How can you get Windows Movie Maker 2.6 to accept mkv and flv files?

Windows Movie Maker will not accept .mkv or .flv files. You have to convert the files to a format compatible with the program before you can import them. Windows Movie Maker is limited in the amount for formats it can import/use.