Printing numbers to letters - Programmers Heaven

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Printing numbers to letters

Posts: 2Member
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

• Posts: 163Member
: 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...[code][color=Blue]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.[/color][/code]