almost there!



Hello, I was wondering if anyone could tell me how I can get cents. I can
get dollars fine but not the right amount of cents.For example, if i input
100 20 10 4 1 1 (pennies,nickels,dimes,quarters,loonies,toonies) i should
get 7 dollars and 0 cents. but i get

Please enter the number of pennies, nickels, dimes, quarters, loonies,
toonies,
each separated by a single space.
100 20 10 4 1 1
7 dollar(s) and 700 cents
Press any key to continue . . .

my code is

// Convert strings to integer values.

int pen1 = Integer.parseInt(pen);
int nick1 = Integer.parseInt(nick);
int dime1 = Integer.parseInt(dime);
int quart1= Integer.parseInt(quart);
int loon1 = Integer.parseInt(loon);
int toon1 = Integer.parseInt(toon);

// Calculates the total cent value.

int coins= (pen1*1) + (nick1*5) + (dime1*10) + (quart1*25)
+ (loon1*100) + (toon1*200);




// Calculate the total dollar value.

int dollars=(coins/100);







System.out.println(dollars +" "+ "dollar(s) " + "and " + coins + " " +
"cents"); // Prints out total money value.

}
}


.



Relevant Pages

  • Re: Rounding error when converting from double to int
    ... So we made a money class where the money ... The cents are stored ... the original double amount contains fractions of a cent (due to some ... then it converts to int. ...
    (comp.lang.c)
  • Re: converting float to double
    ... > Dik T. Winter wrote: ... > modified rounding, principal ... When the amount is 10769 cents (3-rd ... int main { ...
    (comp.lang.c)
  • Re: Lcc win overflow handling
    ... signed (long int) count of cents for each line item. ... enough the combined finances of the planet could not possibly overflow ... $92,233,720,000,000,000 - assuming you're working in cents. ... hyperinflation doesn't seem too likely to exceed that... ...
    (comp.lang.c)
  • Re: Product Class #2
    ... Note though that for accuracy reason it's best to store currency as an ... cents, not a float of dollars so then it would look like this: ...
    (comp.lang.ruby)
  • Re: how to format bigdecimal corectly?
    ... so is the BigDecimal I got from long rounded or just the string format is ... Either case I still have a problem but if it is only from format the ... You could have a constructor that takes an amount in cents and a method ) that returns that amount formatted how you wish. ... private final int cents; ...
    (comp.lang.java.help)