Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Printing numbers to letters Posted by darkwave0 on 7 Feb 2010 at 4:25 PM
How can I using procedures create A program that works like:

A program that takes the input from user in form of real numbers (4975.11)
and outputs like:

Four Thousand Nine Hundred Seventy Five and Eleven Cents
Report
Re: Printing numbers to letters Posted by _Atex_ on 8 Feb 2010 at 12:01 AM
: How can I using procedures create A program that works like:
:
: A program that takes the input from user in form of real numbers
: (4975.11)
: and outputs like:
:
: Four Thousand Nine Hundred Seventy Five and Eleven Cents
:

Here's a simple code to give you an idea how to implement it. Although it supports only the [-100..100] integer range...
const tens:array[0.. 9] of string[10]=('','Ten','Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety');
      ones:array[0..19] of string[10]=('','One','Two','Three','Four','Five','Six','Seven','Eight','Nine','Ten',
                                       'Eleven','Twelve','Thirteen','Fourteen','Fifteen','Sixteen','Seventeen',
                                       'Eighteen','Nineteen');

var r,t,o:integer;

begin
 repeat
  write('Enter a value (0 to exit): ');readln(r);
  if r<0 then write('Negative ');
  r:=abs(r);
  if r>100 then writeln('Must be less then 100') else
   if r=100 then writeln('One Hundred') else begin
    t:=r div 10;
    o:=r mod 10;
    if r=0 then writeln('Zero') else
     if t=0 then writeln(ones[o]) else
      if t=1 then
       if o=0 then writeln(tens[t]) else writeln(ones[10+o]) else
        writeln(tens[t]+' '+ones[o]);
  end;
  writeln;
 until r=0;
end.




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.