By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,611 Members | 1,642 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,611 IT Pros & Developers. It's quick & easy.

Help requested for program to "calculate coin change"

P: 10
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
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
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

Post your reply

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