need to have an input of money to pay for an item and amount given.

to return change due with denomination format:

``````20 dollar bills
10 dollar bills
5 dollar bills
1 dollar bills
quarters
nickels, dimes, pennies, etc.
``````

so far i got this:

``````import java.util.Scanner;

public class Cashier
{

//*****************************************************************
// Creates change to be given to customer from cashier.
//*****************************************************************

public static void main(String[] args)
{
double a;
double b;

Scanner scan = new Scanner (System.in);
System.out.print ("Enter total amount:\$ ");
a = scan.nextDouble();

System.out.print ("Enter amount given:\$ ");
b = scan.nextDouble();

System.out.print ("Change:\$" + (b - a)  );

}
}
``````

## All 3 Replies

First, before you do any programming, grab a piece of paper and plan what you think should happen.

You need to devise an algorithm to give the least number of coins when you get change from a note.

When you've got that then we shall sort out your program. :eek:

``````import java.util.Scanner;

public class Cashier
{

//*****************************************************************
// Creates change to be given to customer from cashier.
//*****************************************************************

public static void main(String[] args)
{
double a;
double b;

Scanner scan = new Scanner (System.in);
System.out.print ("Enter Total Price: \$");
a = scan.nextDouble();

System.out.print ("Enter Payment: \$");
b = scan.nextDouble();
System.out.println();
System.out.println ();
System.out.println ("Total Price:         \$" + a);
System.out.println ("Your Payment:        \$" + b);

System.out.print ("Change:              \$" + (b - a)  );

}
}
``````

Here's some tips. Represent the total amount of money in cents. Represent the \$20,\$5,\$10,\$1 in cents as well. Start with the largest denomination you need to find, \$20, and work down from there. Use modulus.

\$20 = 2,000 cents

\$56.73 = 5,673 cents

It'll be easier working with the whole numbers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.