Click to See Complete Forum and Search --> : Cheque printing


X-factor
October 2nd, 2005, 11:20 PM
Hi everyone!

I'm new to C programming and it is most grateful if someone could help me with my small project here.

I'm looking for a source code of a program that can read numbers entered by a user e.g., 1300.70 and then all the numbers will be printed on a cheque in a segmented way such as "1 thousand 3 hundred and 70 cents".

I believe there's someone helpful enough to help me..

Many thanks. :D

SuperKoko
October 3rd, 2005, 02:48 AM
Here is how you can do:

Multiply the floating point number by 100, and round to the nearest integer, so you found 130070.
Get the number modulo 100 - it returns 70 (number of cents)
Divide (euclidian division) the number by 100 and compute the result modulo 100 - it returns 0 (number of units)
Divide the already-divided number, by 10 - it returns 3 (number of hundreds)
Continue to divide the number by 10 - it returns 1 (number of thousands)
Then output the number with std::cout. Don't output the nul parts of the number


To do that, you can use unsigned integers or floats.
With floats, you should need to use floor, and /, and optionally fmod.
With integers you should need to use % and /.