473,385 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Need help with code to prompt for and read double for monetary unit.

2
Hi I need to do a program that will prompt for and read a double value representing a monetary amount.Then determine the fewest numbers of each bill and coin needed to represent that amount, starting with the highest (maximum size needed is a ten dollar bill).
For example if the value entered is 47.63 then the program should print:
4 ten dollar bills
1 five dollar bills
2 one dollar bills
2 quarters
1 dimes
0 nickels
3 pennies
Thanks for your help!
Sep 12 '06 #1
2 2337
D_C
293 100+
After you read the double, you should store it as an integer, as the number of cents. For example, $47.63 = 4,763 cents.

Always take the most as you can at once. Take as many $10s, then $5s, then $1s, until you account for all the money.

$10 is equivalent to 1000 pennies, and $47.63 is 4763 pennies. You can take 4763 (integer divide) 1000, or 4 $10 bills. and then you will have 4763%1000, or 763 pennies left over. Now do the same thing for $5 dollars with the 763 remaining pennies. 763/500 = 1, 763%500 = 263.

You could use a loop to do it, but you also should address making sure you have the plurality correct. Penny or pennies, for example. Consider $16.43. That should be one of each. I suppose you could just put ten(s), five(s). It still doesn't help for penny or pennies though.
Sep 12 '06 #2
java06
2
After you read the double, you should store it as an integer, as the number of cents. For example, $47.63 = 4,763 cents.

Always take the most as you can at once. Take as many $10s, then $5s, then $1s, until you account for all the money.

$10 is equivalent to 1000 pennies, and $47.63 is 4763 pennies. You can take 4763 (integer divide) 1000, or 4 $10 bills. and then you will have 4763%1000, or 763 pennies left over. Now do the same thing for $5 dollars with the 763 remaining pennies. 763/500 = 1, 763%500 = 263.

You could use a loop to do it, but you also should address making sure you have the plurality correct. Penny or pennies, for example. Consider $16.43. That should be one of each. I suppose you could just put ten(s), five(s). It still doesn't help for penny or pennies though.
Yes but is asking me to use a double value. I am still having problems. I am having trouble to do the code for calculation.
Sep 12 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: wane | last post by:
Hello, I have heard that one should avoid using float and double in monetary calculation because of the lack of preciseness. What is a good alternative? Thanks
0
by: south622 | last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past...
6
by: Java1963 | last post by:
Need help with writting an application that prompt for and read a double value representing a monetary amount. -------------------------------------------------------------------------------- ...
5
sammyboy78
by: sammyboy78 | last post by:
I'm trying to create a program that continuously asks for user input until the user inputs "stop" for employee name which will terminate the program. I have compiled the following code but when the...
1
by: twin2003 | last post by:
need help with inventory part 5 here is what I have to do Modify the Inventory Program by adding a button to the GUI that allows the user to move to the first item, the previous item, the next...
4
by: civicjai | last post by:
Can anyone teach me how to An item code is to be entered by the user. If it is an existing item code that matches an item in the items array , a description of the item with its unit price is...
1
by: tikney5 | last post by:
I need to modify my current program so that is uses a class to store and retrieve the employees name, hourly rate, and number of hourse worked. Use a constructor to initialize the employee...
3
by: 100grand | last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.