ok i am writing a program that ask for the amount total and amount tender.
then i'm supposed to calculate a combined amount of coins and dollars to make up the change amount.

i know how to split out the dollar amount, but i'm stuck on how to calculate the combined amount of coins.

i can't use the if/else commands.

can somebody please give me a hint??? you don't have to write any code for me, but just help me on the math part.

ok nevermind the above post. i need a new way to extract the dollar amount. for example if the change is 5.26, i need a way to read the "5."

i've previously converted it to a string and then read it from there, but then things got complicated. do i need to convert the string back to a double or something to do math?

Okay, so you can't use ifs, that means you have to use integer arithmetic.

Think of it this way: if you need to give $1.52 in quarters, dimes, nickels and pennies, one way to do it would be to take .25 at a time out of that sum until there was less than a quarter. After that, you can take dimes until you're under a dime, then you take as many nickels as you can, then you give one penny at a time.

Looking at your post above - don't try to do this with Strings. Make yourself an integer. $5.26 is 526 cents, do your calculation on that integer value. It'll be much easier to deal with. (you can modify the procedure I outlined to deal with dollars pretty easily as well)

Have fun, come back with your code or on it.

This is an inefficient procedure, but I think you can probably write it easily enough, and without any ifs (or ands or buts, for that matter!)

Once you've written that, we can talk about improving it.

0

coil

By the way, if you do need to convert:

Most primitives have a wrapper-class toString() method. int->String: Integer.toString(i); Most primitives also have a conversion from String method as well. String->int: Integer.parseInt(i); Therefore, for something like char to int: Integer.parseInt(Character.toString(c));

i just divided the change amount by 1, then use the reminder to divide by .25, then by .10, and so on. then i converted the doubles to int and display the output. it works!!!

Cool. The fact that you worked out the division part from what you were given is pretty good, it shows that you're thinking about what you're doing. Good work.

You should probably take a little time to look at floating point arithmetic at some stage. Floating point representation in computers is necessarily inexact, and you might run into trouble with comparison of values. It's possible, for example, that two values which should be equal will differ somewhere out in the godknows-th decimal place - and then they won't be equal. For discrete quantities like money, it's usually best to use ints, to avoid these errors.

I want to implement undo logic which deletes the last drawn shape. To test this logic i had cleared shapes list and redrawn all shapes but still last ...