473,386 Members | 1,745 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,386 software developers and data experts.

Help requested for program to "calculate coin change"

import java.util.Scanner;
public class ChangeDue2
{
public static void main(String [] args)
{
double purchase, tendered, change;
int dollars, quarters, dimes, nickels, pennies;

Scanner keyboard=new Scanner(System.in);
System.out.print("Enter amount of purchase");
purchase=keyboard.nextDouble();
System.out.println("Enter amount tendered");
tendered=keyboard.nextDouble();

change = tendered - purchase;
dollars = (int) (change / 100.00);
change = change - dollars * 100;
quarters = (int)(change / 25);
change = change - quarters * 25;
dimes = (int)(change / 10);
change = change - dimes * 10;
nickels = (int)(change / 5);
change = change - nickels * 5;
pennies = (int)(change / 1);
change = change - pennies;


System.out.println("The amount tendered was: " + tendered);
System.out.println("The purchase amount was: " + purchase);
System.out.println("Your change is: " + change);
System.out.println("The number of dollars is: " + dollars);
System.out.println("The number of quarters is: " + quarters);
System.out.println("The number of dimes is: " + dimes);
System.out.println("The number of nickels is: " + nickels);
System.out.println("The number of pennies is: " + pennies);


}
}
my program is suppose to show my due change and i got it working but my change and coins are wrong how can i improve it thank you..(its supposed to be in java)
Feb 7 '08 #1
1 16419
r035198x
13,262 8TB
my program is suppose to show my due change and i got it working but my change and coins are wrong how can i improve it thank you..(its supposed to be in java)
You used the quote button for your code. You should have used the code (#) button instead.
Have a look at the threads in this forum right now. There are a couple of them dealing with the same problem as yours.
Feb 7 '08 #2

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

Similar topics

2
by: Mindful_Spirit | last post by:
I'm trying to set up a basic email feed back form like this, and was wondering about some basic configuration settings. I have used code from this website. I have it working just fine. I'm...
19
by: Christian Fowler | last post by:
I have a VERY LARGE pile of geographic data that I am importing into a database (db of choice is postgres, though may hop to oracle if necessary). The data is strictly hierarchical - each node has...
10
by: Clint | last post by:
Hey all - I'm having a really confusing problem concerning a web service. Right now, I have an application that needs to call a web service that does nothing but return "true" (this will...
0
by: James Thompson | last post by:
I have the book "Microsoft Visual C++ .NET Step by Step" for Visual Studio .NET 2002. Well, I am currently using Visual Studio .NET 2003. In chapter 2 of this book, it tell me to create a new...
4
by: LP | last post by:
Hi, My webservice is currently deployed on WIndows 2000 server and runs pretty fine. I am trying to run my webservice on a Windows 2003 server. My webservice tries to write to a eventlog. The...
3
by: Michele Petrazzo | last post by:
Hi, I'm trying a script on a debian 3.1 that has problems on shelve library. The same script work well on a fedora 2 and I don't know why it create this problem on debian: #extract from my code...
7
by: Peter Ritchie | last post by:
I'm writing a Web Service and I would like to add performance counter data for monitoring performance of the Web Service's operations over time and load. The problem is, I get the "Requested...
13
by: arnuld | last post by:
this is the code: ------------------------------------------------------------------------- #include <iostream> #include <string> #include <vector> struct Pair { std::string name;
2
by: 1ontherun | last post by:
Hi, Here's the problem. I am trying to allow the user to change a page background to an image file on their computer. The input box is already a 'type=file', however it uses the character "\"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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.