CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Cheque printing

  1. #1
    Join Date
    Oct 2005
    Posts
    1

    Talking Cheque printing

    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.

  2. #2
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    Re: Cheque printing

    Here is how you can do:
    1. Multiply the floating point number by 100, and round to the nearest integer, so you found 130070.
    2. Get the number modulo 100 - it returns 70 (number of cents)
    3. Divide (euclidian division) the number by 100 and compute the result modulo 100 - it returns 0 (number of units)
    4. Divide the already-divided number, by 10 - it returns 3 (number of hundreds)
    5. Continue to divide the number by 10 - it returns 1 (number of thousands)
    6. 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 /.
    "inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
    Club of lovers of the C++ typecasts cute syntax: Only recorded member.

    Out of memory happens! Handle it properly!
    Say no to g_new()!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured