#Need help with basic Java assignment

6 messages · Page 1 of 1 (latest)

dark thunder
#

So I need to do this with minimum code, and no if/else statement. With very basic and introductory java. For some reason, I'm having a hard time thinking through how to do this when I know the answer is so simple. Here is the assignment
"Write a program that prompts the user to enter two double values, the first one the amount due on a bill and the second item the amount of money given to the clerk. The program must make change with dollar bills, quarters, dimes, nickels, and pennies. The clerk does not have any 50 cent pieces. For this program, we can assume the amount of money given is equal to or greater than the amount due. Sample out shown below. The output needs to be readable but does not have to match pecisely."

Here is the code I have so far.

        
        Scanner  input = new Scanner(System.in);
        // prompt user to input cost of purchase
        System.out.println("Enter the total cost of the purchase");
        
        // store user input as totalCost
        double totalCost = input.nextDouble();
        
        // prompt user to input amount of money they gave to clerk
        System.out.println("Enter the amount of money given to the clerk");
        
        // store user input as amountGiven
        double amountGiven = input.nextDouble();
        
        double totalChange = amountGiven - totalCost;
dusty roostBOT
#

This post has been reserved for your question.

Hey @dark thunder! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

dark thunder
#

Need help with basic Java assignment

#

I can't figure out what logic to use to determine how many Dollars, Quarters, Nickles and Dimes to return

earnest portal