Results 1 to 5 of 5

Thread: need fast reply from pascal programmer plz

  1. #1
    99shassan's Avatar Poster BT Rep: +1
    Join Date
    Jul 2003
    Posts
    787
    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

    Code:
      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?
    Changed SPAN settings in sig a YEAR after it was removed

  2. Internet, Programming and Graphics   -   #2
    4play's Avatar knob jockey
    Join Date
    Jan 2003
    Location
    London
    Age
    41
    Posts
    3,824
    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.

  3. Internet, Programming and Graphics   -   #3
    99shassan's Avatar Poster BT Rep: +1
    Join Date
    Jul 2003
    Posts
    787
    i need it so that there can't be any letters. but havn't succeeded
    Changed SPAN settings in sig a YEAR after it was removed

  4. Internet, Programming and Graphics   -   #4
    4play's Avatar knob jockey
    Join Date
    Jan 2003
    Location
    London
    Age
    41
    Posts
    3,824
    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

    Code:
    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.
    Last edited by 4play; 12-16-2005 at 01:08 AM.

  5. Internet, Programming and Graphics   -   #5
    JimmyP
    Guest
    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.

    Code:
    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.

Bookmarks

Posting Permissions

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