homework help

We are trying to understand how to assign a name to a digit. We are taking a nummerical amount (float) such as $123.42 and need it to display one hundred twenty three dollars and 42 cents. We know how to break down 123 into separate digits and we know how to display the words hundred, dollars and cents but we do not know how to have "1" display as "one" or "20" as "twenty". we have a char array listing all of the words
first get rid of the fact that its a float. (I not sure but I think you should)
int costint=123.42*100;

(costint%10)/1=2
(costint%100)/10=4
(costint%1000)100=3

and etc...

Does the 42 have to be words as well?
Getting the front is easy.
First duplicate your float to an int. That will truncate the 42 off the end so you'll be left with 123, store in an integer.
then make a divisor that is only as big as the highest place:

1
2
3
divisor = 1;
while ((divisor*10) < floatFrontInteger)
    divisor *= 10;


Then just us the divisor to out put the place value like hundreds or thousands.
remainder = floatFrontInteger / divisor; // get current digit and then output name and place via divisor;
So if remainder is 2 and divisor is 100, then you need to write the script to print out two hundred.
Topic archived. No new replies allowed.