PDA

View Full Version : need fast reply from pascal programmer plz



99shassan
12-15-2005, 11:06 PM
Hi guys, I got a problem again. I have to go back to the old program I was creating. I need to add an accept phone number code in there which i have at the end


BEGIN
writeln('Enter Customer Phone Number:'); {Ask to enter Phone number}
readln(phonenumber);

end;


However, I want to add a loop in there so that it will go back if a letter is entered as a phone number.

Can anyone help?

4play
12-16-2005, 12:51 AM
Its been a while since i used pascal but you dont seemed to have declared the phonenumber variable.

its also a bad idea to have it as an interger since people like to add in dashes and spaces into phone numbers. store it as a string.

sorry no idea if there is a function to look at an int and see if it contains letters.

99shassan
12-16-2005, 12:52 AM
i need it so that there can't be any letters. but havn't succeeded :(

4play
12-16-2005, 01:00 AM
have you tried declaring phonenumber as an int and sees what happens with letters ?
does it crash?
has your teacher given you a function to use in previous examples to examine an int for chars ?
just looking through some of my old work now to see if i have done something similar.

edit: i would imagine the psudeo code is something like




while phonenumber contains chars do

begin
print "input phone number"
input "phone number"
end


that should loop around until the phonenumber contains no chars but i dont have a clue what the function is you need to use.

JimmyP
12-30-2005, 05:19 PM
This is in Delphi (Object Pascal) but you should get the idea. Bascially, declare the phone number as an integer, then trap the exception that would occur if they enter a character.

If you want to go back up so they have to enter it again, just use a label.



program Project2;

{$APPTYPE CONSOLE}

uses
SysUtils;

var
phonenumber :integer;

begin
writeln('Enter Customer Phone Number:');
try
readln(phonenumber);
except
writeln('Oops, you enter something other than 0-9');
end;
writeln('done');
readln;

end.