[URGENT] Due in 1.5 hrs. VERY easy java project question
This is the assignment: Write an interactive program to calculate the change (quarters, dimes, nickels,
pennies) from an amount entered. For example, if the user inputs 1.47, the program
should display the following:
1.47 is equivalent to the following:
5 quarters
2 dimes
0 nickels
2 pennies
*** End of Program ***
However, when I do this, let's say I enter 1.26, it tells me:
Code:
Enter the cash amount:
1.26
1.26 is equal to the following:
5.04 Quarters
1.26 is equal to the following:
12.6 Dimes
1.26 is equal to the following:
25.2 Nickels
1.26 is equal to the following:
126.0 Pennies
***End of Program***
I want it to tell me 5 quarters, 0 dimes, 0 nickels, and one penny. Any idea how I could change it so that works?
This is my code -
Code:
//************************************************************************
// Name: TJ Class: CSC 120 Assignment: Program 1
//
//Due Date: Septemeber 28th, 11:59 PM
//
// Purpose: To display number of
// Quarters, Nickels, dimes, and pennies in a dollar amount. (Ex. $1.28)
//************************************************************************
package program1;
import java.util.Scanner;
public class CSC120Program1 {
public static void main(String[] args)
{
double cash;
double Q = 0.25, coins;
Scanner scan = new Scanner (System.in);
System.out.print("Enter the cash amount: \n");
cash = scan.nextDouble();
coins = cash / Q;
System.out.println(cash + " is equal to the following:\n" + coins + " Quarters " + "\n");
Q = 0.10;
coins = cash / Q;
System.out.println(cash + " is equal to the following:\n" + coins + " Dimes " + "\n");
Q = 0.05;
coins = cash / Q;
System.out.println(cash + " is equal to the following:\n" + coins + " Nickels " + "\n");
Q = 0.01;
coins = cash / Q;
System.out.println(cash + " is equal to the following:\n" + coins + " Pennies " + "\n");
System.out.println("***End of Program***");
}
}
Re: [URGENT] Due in 1.5 hrs. VERY easy java project question
Don't use [URGENT] in the title.