i have to write a program that has to subtract the purchase price from 100 and then determine the number of qtr,dms,nkls,pns.. when i run it my results are in decimal am not sure how to change it..any advice thanks alot..


import java.util.Scanner;
public class Subtract
{
public static void main(String [] args)
{
double purchase,change,quarters,dimes,nickels,pennies;
Scanner keyboard=new Scanner(System.in);
System.out.println("Enter purchase amount under 1.00:");
purchase=keyboard.nextDouble();

change=100-purchase;
quarters=change/25;
dimes=change/10;
nickels=change/5;
pennies=change/1;


System.out.println("Enter purchase amount: " + purchase);
System.out.println("The change is: " + change);
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);
}
}

quarters, dimes, nickels, pennies must be int

quarters= int(change/25);
dimes= int(change/10);
nickels= int(change/5);
pennies= int(change/1);

Also, your calculation isn't keeping track of the remainder after the higher coins have been returned. If you have 0.70 in change, your current calcs would show 2 quarters, 7 dimes, 14 nickels, etc. I think you want to display 2 quarters, 2 dimes as the result.

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.