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