#### Howdy, Stranger!

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

#### Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# how do you convert a written number in to a digit number???

I am trying to write a program where you prompt a user to input a 3 digit number written in text... ie.. one hundred thirty-five & have it output 135.

I am having so much trouble with this. I am very very new to Pascal & I am not grasping the concepts at all.

For right now... I am trying to just get the 1 out... not worried about the rest.... I am entering a one in & all I can get is a one back. HELP ME!

CONST
one='1';
VAR
dignum:
integer;
wrtnum:
string;
(**********************************************************)
BEGIN
Write('Please enter a 3-digit number in text:');
Read(wrtnum);
write(wrtnum);

IF wrtnum = one
THEN dignum = 1
END.

I know this is probably nowhere being correct... but I am totally lost. My book doesn't help & I haven't found anything on any sites that references this.

what is the alcoholic statistics for Pascal Programmers???? Cause I swear its enough to drive you to drinking! :(
· ·

## Comments

• Posts: 241Member
: I am trying to write a program where you prompt a user to input a 3 digit number written in text... ie.. one hundred thirty-five & have it output 135.
:
: I am having so much trouble with this. I am very very new to Pascal & I am not grasping the concepts at all.
:
: For right now... I am trying to just get the 1 out... not worried about the rest.... I am entering a one in & all I can get is a one back. HELP ME!
:
: CONST
: one='1';
: VAR
: dignum:
: integer;
: wrtnum:
: string;
: (**********************************************************)
: BEGIN
: Write('Please enter a 3-digit number in text:');
: Read(wrtnum);
: write(wrtnum);
:
:
: IF wrtnum = one
: THEN dignum = 1
: END.
:
: I know this is probably nowhere being correct... but I am totally lost. My book doesn't help & I haven't found anything on any sites that references this.
:
: what is the alcoholic statistics for Pascal Programmers???? Cause I swear its enough to drive you to drinking! :(
:
Try
[code]
IF wrtnum = 'one' THEN dignum =1;
[/code]
Make yourself a table of constants to hold the strings ['one', 'two']. Try some more code. This looks a lot like schoolwork. Drinking is bad for your liver...
· ·
• : : I am trying to write a program where you prompt a user to input a 3 digit number written in text... ie.. one hundred thirty-five & have it output 135.
: :
: : I am having so much trouble with this. I am very very new to Pascal & I am not grasping the concepts at all.
: :
: : For right now... I am trying to just get the 1 out... not worried about the rest.... I am entering a one in & all I can get is a one back. HELP ME!
: :
CONST
one='one';
two='two';
three='three';
four='four';
five='five';
six='six';
seven='seven';
eight='eight';
nine='nine';
ten='ten';
VAR
wrtnum:
string;
dignum,
outerror:
integer;
(**********************************************************)
BEGIN
Write('Please enter a 3-digit number in text:');
Read(wrtnum);

Val(wrtnum,dignum,outerror);

writeln(outerror);
END.

***Yes this is homework & I'm totally lost in this class. Trying to hit message boards to find insight since I am not picking it up.

I changed my code to the above.... it compiles... once I enter one... it outputs 2... i close down the dos window & try it again this time entering two.. it ouputs 1 still???

Yes drinking is bad for your liver... but I am starting to believe that Pascal is bad for my total health! :)

: :
: Try
: [code]
: IF wrtnum = 'one' THEN dignum =1;
: [/code]
: Make yourself a table of constants to hold the strings ['one', 'two']. Try some more code. This looks a lot like schoolwork. Drinking is bad for your liver...
:

· ·
• Posts: 241Member
: : : I am trying to write a program where you prompt a user to input a 3 digit number written in text... ie.. one hundred thirty-five & have it output 135.
: : :
: : : I am having so much trouble with this. I am very very new to Pascal & I am not grasping the concepts at all.
: : :
: : : For right now... I am trying to just get the 1 out... not worried about the rest.... I am entering a one in & all I can get is a one back. HELP ME!
: : :
: CONST
: one='one';
: two='two';
: three='three';
: four='four';
: five='five';
: six='six';
: seven='seven';
: eight='eight';
: nine='nine';
: ten='ten';
: VAR
: wrtnum:
: string;
: dignum,
: outerror:
: integer;
: (**********************************************************)
: BEGIN
: Write('Please enter a 3-digit number in text:');
: Read(wrtnum);
:
: Val(wrtnum,dignum,outerror);
:
:
: writeln(outerror);
: END.
:
: ***Yes this is homework & I'm totally lost in this class. Trying to hit message boards to find insight since I am not picking it up.
:
: I changed my code to the above.... it compiles... once I enter one... it outputs 2... i close down the dos window & try it again this time entering two.. it ouputs 1 still???
:
: Yes drinking is bad for your liver... but I am starting to believe that Pascal is bad for my total health! :)
:
: : :
: : Try
: : [code]
: : IF wrtnum = 'one' THEN dignum =1;
: : [/code]
: : Make yourself a table of constants to hold the strings ['one', 'two']. Try some more code. This looks a lot like schoolwork. Drinking is bad for your liver...
: :
:
:
OK. I don't want to turn this into one of those threads that won't die, but you don't want to use val. That is used to do a type conversion from string to number. You will probably want to prompt the user to use spaces or dashes to separate the words. You will have to parse their input into individual words. If you make your constants an array, then you can quickly scan thru the array and find a match. Since the user can enter a mixture of cases, you might want to convert their input into all caps. If you think thru the way you make your arrays, the *index* into the array can be used to determine the numeric equivalent of the string. I suppose you could also use a giant case statement. BTW, your "writeln(outerror)" is printing the error code for your conversion which is non-zero indicating that the function is not returning a valid number. KEEP TRYING. Pascal is a good way to learn to program. That's why your university is having you take it.....good luck.
· ·
• Posts: 1Member
[b][red]This message was edited by Raadya at 2003-11-3 4:8:33[/red][/b][hr]
[pre]
Hi, I don't know good english, but I try help to you

here is a program for conversion any word-number to a digital form.

uses CRT;
var
cr,x,y,expnt:byte;
c:char;
delka,cislo:word;
slovo:string;
vysledek:word;
numbers:array[1..4] of string;

const
digits: array[0..20] of string=
'zero','one','two','three','four','five','six','seven','eight','nine', 'ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen','twenty';
digits2:[3..9] of string=
'thirty','forty','fifty','sixty','seventy','eighty','ninety';

begin
ClrScr;
Write ('What is the number? ');
readLN (slovo);

delka:=length(slovo);
cr:=1;
y:=1;
for x:=1 to 4 do numbers[x]:='';

{ this makes from word e.g. 'thirty-five' two words "thirty" and "five" '}
for x:=1 to delka do
begin
if (slovo[x]<>' ' OR (slovo[x]<>'-')) then
numbers[cr]:=numbers[cr]+slovo[x] else cr:=cr+1;
{ one didit ends with the mark or - }
end;

for x:=cr downto 1 do
begin
for y:=0 to 20 do
begin
if numbers[x]=digits[y] then
begin
vysledek:=vysledek+y*expnt;
expnt:=1;
end;

for y:=3 to 9 do
if numbers[x]=digits2[y] then vysledek:=vysledek+y*10;

if numbers[x]='hundert' then exp:=100;
end;

Writeln(' and in digitals is it: ', vysledek);

Writeln;
Writeln(' Press ENTER to end of this program');
ReadLN;
end.

I hope, it will go...
I write it in the school and I havent any shance to try it...

When you will have any questions, write to me at: cz609361@tiscali.cz

Bye

Radim as raadya here :-)

[/pre]

· ·
Sign In or Register to comment.