Results 1 to 2 of 2
- 09-29-2011, 04:19 AM #1
Member
- Join Date
- Sep 2011
- Posts
- 1
- Rep Power
- 0
[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:
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?Java 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***
This is my code -
Java 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***"); } }
- 09-29-2011, 06:38 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Re: [URGENT] Due in 1.5 hrs. VERY easy java project question
Don't use [URGENT] in the title.
Similar Threads
-
Project Question Urgent?
By newtocs in forum New To JavaReplies: 1Last Post: 10-09-2009, 02:55 PM -
general confused about java question (easy!)
By sweetjava in forum New To JavaReplies: 1Last Post: 08-09-2009, 02:03 AM -
New to Java and have an easy question
By JBOY08 in forum New To JavaReplies: 1Last Post: 11-19-2008, 07:40 PM -
Easy program...need help (urgent)
By Zebra in forum New To JavaReplies: 25Last Post: 05-30-2008, 08:51 AM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks