473,544 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Money program

KoreyAusTex
36 New Member
I am having a very hard time making this program work right, I am sort of lost and I was wondering if I might get some advice.

This is what I have so far but I have a rounding error when I use the amount 10.03:

Expand|Select|Wrap|Line Numbers
  1. public class Money
  2.     public static void main(String[] args)
  3.     { 
  4.         double TOTAL_AMOUNT = 10.03;
  5.  
  6.         int money = (int)(TOTAL_AMOUNT * 100);
  7.  
  8.         System.out.println("Your money amount " + TOTAL_AMOUNT + " consists of");
  9.  
  10.         System.out.println("\t" + (money / 100) + " dollars");
  11.  
  12.         money = money % 100;
  13.  
  14.         System.out.println("\t" + (money / 25) + " quarters");
  15.         money = money % 25;
  16.  
  17.         System.out.println("\t" + (money / 10) + " dimes");
  18.         money = money % 10;
  19.  
  20.         System.out.println("\t" + (money / 5) + " nickels");
  21.         money = money % 5;
  22.  
  23.         System.out.println("\t" + (money / 1) + " pennies");
  24.     }
  25. }
I know Math.round() is a useful class but can't figure how to put it in my program
Feb 5 '08 #1
7 2974
Ganon11
3,652 Recognized Expert Specialist
Do you need to use a floating point (decimal) number to hold the money? I see you immediately convert it to an integer - maybe you should just start with an integer.
Feb 5 '08 #2
hollywood115
16 New Member
You're problems is that you're not using Math.round.

just replace:
int money = (int)(TOTAL_AMO UNT * 100);
with:
int money = (int)Math.round (TOTAL_AMOUNT * 100);

it should round a lot more accurately now, try it out.

hope it helps :)

I am having a very hard time making this program work right, I am sort of lost and I was wondering if I might get some advice.

This is what I have so far but I have a rounding error when I use the amount 10.03:

Expand|Select|Wrap|Line Numbers
  1. public class Money
  2.     public static void main(String[] args)
  3.     { 
  4.         double TOTAL_AMOUNT = 10.03;
  5.  
  6.         int money = (int)(TOTAL_AMOUNT * 100);
  7.  
  8.         System.out.println("Your money amount " + TOTAL_AMOUNT + " consists of");
  9.  
  10.         System.out.println("\t" + (money / 100) + " dollars");
  11.  
  12.         money = money % 100;
  13.  
  14.         System.out.println("\t" + (money / 25) + " quarters");
  15.         money = money % 25;
  16.  
  17.         System.out.println("\t" + (money / 10) + " dimes");
  18.         money = money % 10;
  19.  
  20.         System.out.println("\t" + (money / 5) + " nickels");
  21.         money = money % 5;
  22.  
  23.         System.out.println("\t" + (money / 1) + " pennies");
  24.     }
  25. }
I know Math.round() is a useful class but can't figure how to put it in my program
Feb 5 '08 #3
BigDaddyLH
1,216 Recognized Expert Top Contributor
Loose the doubles and use ints -- cents.
Feb 5 '08 #4
KoreyAusTex
36 New Member
Loose the doubles and use ints -- cents.
My professor wanted it in the format of 10.03 or 15.34. She didn't let us break it up, if I understand you correctly?
Feb 9 '08 #5
BigDaddyLH
1,216 Recognized Expert Top Contributor
My professor wanted it in the format of 10.03 or 15.34. She didn't let us break it up, if I understand you correctly?
Well, I'm not sure to say since I don't know the whole story, but if I were writing the program for my own benefit, I would work with ints, and merely format the output to look "15.34".

If you have time, ask your professor to clarify things for you.
Feb 9 '08 #6
missdaisy14
1 New Member
This is very helpful. But what if the output is 0 and you don't want it to show in the results?
Jul 9 '13 #7
Nepomuk
3,112 Recognized Expert Specialist
You can always catch specific cases with an if branch. When working with integers, you'd simply put something like this:
Expand|Select|Wrap|Line Numbers
  1. if(money / 25 > 0) {
  2.     System.out.println("\t" + (money / 25) + " quarters");
  3. }
You could even use an if-else structure to give a more natural response:
Expand|Select|Wrap|Line Numbers
  1. if(money / 25 > 0) {
  2.     System.out.println("\t" + (money / 25) + " quarters");
  3. } else {
  4.     System.out.println("\tNo quarters");
  5. }
There are shorter ways of doing this, but this is the easiest to understand.
Jul 9 '13 #8

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

Similar topics

1
1085
by: =?Utf-8?B?R29vZFRyb3VibGU=?= | last post by:
Anyone know if / how it is possible to either disable, or reset the "trended items" in Microsoft Money 2004?? It is very frustrating, I know the program would work if I could clear out all the old numbers from previous income and such. Please help.
0
1602
by: =?Utf-8?B?dHJvdWJsZWQgTVMgTW9uZXkgMjAwMiB1c2Vy?= | last post by:
All of the sudden I seem to have trouble signing into my Microsoft Money 2002 account. When I fire up the program and enter my password I get this message: “Money is unable to verify your Online sign-in….” I have a Windows XP Pentium 4 computer with no recent changes. Here is what I have tried so far with no success: 1. Verified...
4
1942
by: ejack | last post by:
Hello! I am having issues with my code. My program is supposed to take a given amount of money (1.33) and tell how many quarters, dimes, nickels and pennies would make up this sum of money. Problem is when I multiply the input by 100, depending on the amount of money entered, I lose a penny. When I enter .34 it comes out correct, but when I...
1
911
by: =?Utf-8?B?bW9uZXkgdXNlciBrc2E=?= | last post by:
Can not start the program from my data file (3yrs data), or from the backup file. Also no "Repair file" option when selecting "File" as stated in HELP. Help appreciated. Thank you
1
2298
by: progman417 | last post by:
My Shareware program (or rather Commerical Program with a time limited demo) used to have sales of around $2,000 per month around 2002, but then I got busy at work and didn't have time to maintain it, so sales dwindled off to about $200 a month or less. I still get the odd sale now and again. Recently whilst looking for a job I've spent...
2
3800
by: compdude | last post by:
Hello everyone, i need some help on my programming in python i am trying to make a program that can ask for information and document it on a excel spreadsheet. Im a beginner programmer and i am really confused :S this is what i have so far: print "Welcome to Money Manager" print "-----------" print
1
1675
by: rockchicx23 | last post by:
i have to develop this snack machine program that makes you chose a snack put money in and give change here is my code so far, what do i use so the program compare the price and money deposited, I also dont know how to initialize the snack prices and the deposited money.I know i declared and initialized them wrong Thank you so much in advance ...
0
7365
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7607
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7772
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7376
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7709
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5909
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5297
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
661
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.