Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here




HI ALL, i am still new to pascal and i cannot figure out how to execute the following bit of code properly. i know that the answer is staring me straight in the face but i just cant see it. i can get it to execute but it doesnt work properly. also would there be an easier way of coding it? please help as i have bee on this for hours.

   write('NOW ENTER TAXCODE > ');
   if (TaxCode[1]<'0')or(TaxCode[1]>'9')and



Two problems,
(1) My version of pascal (I tried turbo pascal 6.0, OK, it's old, so this might not apply everywhere) cannot readln an array. You need to read each individual item of the array:

  q : word;
  taxcodes : array[0..4] of word; (or whatever)

  for q := 0 to 4 do

(2) All those ands in your first mega-if need to be ors. You want it to object if any of the tax codes is wrong, not if all of them are wrong.

(3) Combining this, the best thing would be to put the test for invalid tax code in the input loop, so it only needs to test the current value and not worry about the rest of the array:

   sillycode = 9999;

  for q := 0 to 4 do
    taxcodes[q] := sillycode;
    while (taxcodes[q] < 0) or (taxcodes[q] > 9)  do

.. or somethign like that.

Good luck


This is what I would do...

program taxcodes;

function IsTaxCode(aCode:string):boolean;
  Digits = ['0'..'9'];
  HiLoChars = ['H', 'L', 'h', 'l'];
  IsTaxCode:= ( Length(aCode) = 4 )
  and ( aCode[1] in Digits )
  and ( aCode[2] in Digits )
  and ( aCode[3] in Digits )
  and ( aCode[4] in HiLoChars );

 write('Enter tax code: ');
 if ( not IsTaxCode(TaxCode) ) then repeat
    writeln('Invalid code, please try again.');
    write('Enter tax code: ');
 until IsTaxCode(TaxCode);


ah, sorry, I didn't notice the h/l bit of the code and misinterpreted your string as an array.
Shame, shame, huge apologies, next time I'll read the the question properly.


thanks for all your help guys. ppc386 especially. this bit of code does work on its own but if i am to insert it into a program, where exactly do i put everything. for instance, this is my first dealing with a 'function' and also with 'boolean' i do know all the boolean gates and what they do but i have never played with them. please help me.


OK, seeing as I made such a mess of replying before, I'll have a go at doing better this time.

(1) Functions

Functions are dead easy. They are just like procedures, except they return a value. Therefore when you declare a function, you have to state that it is a function,
and what sort of value it returns. Here are some examples:

procedure MyProc(a, b : word);
function MyFunc(a, b : word) : longint;

Both expect to be called with two parameters (words) in brackets after them, but the second will return a long int value.

Functions return a single value. For example, you can't return two words and a pointer in the same way as you can pass two words and a pointer. Pity.

So when you call a function, obviously you will (normally) want to call it in a way that collects the value, so instead of writing
MyProc(1, 2)
you will call it as
MyVar := MyFunc(1, 2);

Now inside the code of the function you have to make clear what's being returned. This isn't done by "return" or anything like that. Instead what you do is assign the value to the function name, treating the function name as though it were a variable.

function MyFunc(a, b : word) : longint;
  MyFunc := a + b;

(2) Booleans

boolean is simply a variable type holding the values true or false. ppc386's function returned one of these. Everything you know about boolean algebra applies; the boolean variables and functions are simply the bits and pieces you need to do boolean algebra in the same way as other variables and functions are what you need to do arithmetic.

(3) Where do I put ppc386's code?

You can put the function declaration anywhere you want provided it is either (a) before the procedures/functions that call it, or (b) declared in advance, or (c) put in a unit and declared in the "interface" section, and this unit is refered to in the "uses" section of any unit that wants to call ppc386's function.

Otherwise I agree with ppc386 about books. Getting pascal books is often not easy in provincial bookshops (pascal being considered a dead language), but libraries will have something.


Nice job, lionhill -
  Wish I could be that good at explaining things...



It might be an idea to post the above book and websites (on learning Pascal) into an FAQ for this forum. I've done the same for the Delphi forum: FAQ102-2794



Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close