Results 1 to 6 of 6
Thread: help with second problematic kid
- 04-02-2011, 10:57 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 35
- Rep Power
- 0
help with second problematic kid
hi again guys, i continued doing the personal projects after the earlier question. the tips that people gave me earlier seemed to be doing the job.
this time it's a whole new problem.
i programed a program which you input a number of different coins and it will tell you how much money you have in coins.
When you DO put in the coin values, you get a wrong value... if you enter 0's for everything, you end up with $0.16000000001.
If you enter 1's for everything, you end up with $4.91, when it should actually be $1.91.
I went through the whole thing 10 times, but I just can't seem to figure it out. Help please?
/* Write an application that determines the value of the coins in a jar and prints the total in dollars and cents. Read integer values that represent the number of quarters, dimes, nickels, and pennies. */
import java.util.Scanner; // importing a scanner which will scan what the users will input.
public class pp0208 {
public static void main (String[] args){
double dollars, half_dollars, quarters, dimes, nickels, pennies; // units that the user will input.
Scanner scan = new Scanner (System.in); // using the scanner that had been imported in the beginning of the program.
System.out.println ("Input number of dollars: "); // input number of dollar coins
dollars = scan.nextDouble ();
System.out.println ("Input number of half-dollars: "); // input number of half-dollars
half_dollars = scan.nextDouble ();
System.out.println ("Input number of quarters: "); // input number of quarters
quarters = scan.nextDouble ();
System.out.println ("Input number of dimes:"); // input number of dimes
dimes = scan.nextDouble ();
System.out.println ("Input number of nickels:"); // input number of nickels
nickels = scan.nextDouble ();
System.out.println ("Input number of pennies:"); // input number of pennies
pennies = scan.nextDouble ();
System.out.println ("The number of coins that you input are: " + dollars + " dollars, " + half_dollars + " half-dollars, " + quarters
+ " quarters, " + dimes + " dimes, " + nickels + " nickels, and " + pennies + " pennies.");
// tells you what you input
dollars = (dollars * 1) + (half_dollars * 0.50) + (quarters * 0.25) + (dimes + 0.10) + (nickels + 0.05) + (pennies + 0.01);
System.out.println ("How much you have is: $" + dollars); // tells you how much you have in coins
}
}
- 04-02-2011, 11:04 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
How come for dimes, nickels and pennies you are adding the values?
Try declaring a total variable and see why happens. The code looks good but I believe you should be multiplying smaller demoninations by the value as well.
By the way, when posting code please wrap it in code blocks to maintain indentation and make it easier for us to read
[co de]
code here
[/code]
Also make the coin variables integers, you don't want someone putting in half a quarter.Last edited by sunde887; 04-02-2011 at 11:07 AM.
- 04-02-2011, 11:07 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 35
- Rep Power
- 0
oh you are awsome!
i guess my untrained eyes are still not seeing the small errors like this.
I feel stupid for staring at this for an hour.
Thank You!
- 04-02-2011, 11:08 AM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
You fixed it?
- 04-03-2011, 10:46 AM #5
Member
- Join Date
- Mar 2011
- Posts
- 35
- Rep Power
- 0
yes! thanks to you! now i am working on the next program that might become the third problematic kid, but this time i am going to try to work on it myself. hope it goes well with it.
- 04-03-2011, 11:04 AM #6
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Similar Threads
-
is this IOException problematic?
By ozzyman in forum New To JavaReplies: 14Last Post: 03-31-2011, 06:34 PM -
CCombo problematic when applied to the reasizable Table column
By anubhavBisaria in forum SWT / JFaceReplies: 0Last Post: 08-03-2009, 08:04 AM -
minimum word length in search problematic
By jocassid in forum Suggestions & FeedbackReplies: 3Last Post: 07-01-2008, 04:24 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks