• entries
38
87
• views
34557

# Spot the error

312 views

Grr. I've been repeatedly putting the same error in my functions all day. I think I've fixed them all now but you never know. Can you spot the deliberate mistake?

// PRE: True// POST: Returns List with identifier from user addedfunction User_bind_Identifier_to_value(List:TRecList):TRecList;var ident : STRING;var  val:STRING;BEGIN  Get_String_From_Prompt('Enter identifier name :',ident);  Get_String_From_Prompt('Enter identifier value :',val);  val:=UpperCase(val);  ident:=UpperCase(ident);  IF (val='TRUE') OR (val='FALSE') THEN    Result:=RecList.Attach(MakeIdentifier(ident,val),List)  ELSE    WRITELN('Error: not a boolean');END;

Quote:
 IF (val='TRUE') OR (val='FALSE') THEN

I've done that sort of thing before, really drives you up the wall trying to find it, and then drives you through the wall when you do find it, doesnt it?

That line works ok. The bug was when the user entered something other than TRUE or FALSE, it wouldn't return the tree so delphi crashes with some cryptic error.

The bad thing is this assignment is only worth 15% of the marks for the whole module (I take 8 modules a year) and I've been working on it for 4 days already! grrr...

ohh, i see why thats okay, i misinterepreted it as being a boolean expression and not user input.
but uh, you can have a value that isnt true or false?
a 'maybe' value? why? Or is it supposed to be true/false but the user can be annoying, as users often are, and put something like yes/no?

Yeah, its to stop users typing in something stupid as the value. It has to be TRUE or FALSE so it can be evaluated later on (using operators AND NAND OR and NOR). But its almost finished [smile], and then on to the other two assignments I've got to cram in. [dead]

## Create an account

Register a new account