0

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);
}
}

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Ezzaral
0

quarters, dimes, nickels, pennies must be int

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

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.