22 a) ii) (1 Viewer)

MacAus91

New Member
Joined
Jul 29, 2008
Messages
17
Gender
Male
HSC
2008
what did you put for the error in the algorithm?
i wrote about the then statement being on the next line, but i dont know if that would affect it... im thinking it must of been something to do with the logic of the code...
 

Terlob

Member
Joined
May 6, 2007
Messages
164
Location
Wagga Wagga
Gender
Male
HSC
2008
I had 3 errors... can't remember them though

EDIT - Wrong question :p
 
Last edited:

sdsdsdsdsd

Member
Joined
Dec 2, 2007
Messages
108
Gender
Undisclosed
HSC
1998
MacAus91 said:
what did you put for the error in the algorithm?
i wrote about the then statement being on the next line, but i dont know if that would affect it... im thinking it must of been something to do with the logic of the code...
I said the error was 'found' turning to 'TRUE' which would end the loop, which I knew was wrong because no language does that.


It looked like this (off the top of my head..):

Code:
IF accountFile.accountNumber = accountNumber 
    THEN found = True
    accountName = accountFile.accountName
    accountAddress = accountFile.accountAddress
ELSE
   READ accountFile
ENDIF
I amended it like this:

Code:
IF accountFile.accountNumber = accountNumber THEN
    accountName = accountFile.accountName
    accountAddress = accountFile.accountAddress
    found = True
ELSE
   READ accountFile
ENDIF
I could not find a real error.
 

ondroo

*Sigh*
Joined
Oct 30, 2007
Messages
53
Gender
Male
HSC
2008
ahh that question was lame. i just said the THEN should be on the line above as it is a syntax error or something :S
 

Fly Kite

Member
Joined
Aug 1, 2008
Messages
82
Gender
Male
HSC
2010
there was a syntax error and something else if i remember correctly.
and i think it was something like
IF found NOT false
or something
 

sdsdsdsdsd

Member
Joined
Dec 2, 2007
Messages
108
Gender
Undisclosed
HSC
1998
Code:
IF NOT [B]found[/B] THEN
Thought that might have been it.
 

ondroo

*Sigh*
Joined
Oct 30, 2007
Messages
53
Gender
Male
HSC
2008
i dont get how it can be anything else... here is the whole algorithm;

Code:
BEGIN FindAccountData(accountNumber, accountName, accountAddress)
   OPEN accountFile
   READ accountFile
   found = false
   WHILE NOT found
         IF accountFile.accountNumber = accountNumber
                 THEN found = true
                         accountName = accountFile,accountName
                         accountAddress = accountFile.accountAddress
                 ELSE
                          READ accountFile
         ENDIF
   ENDWHILE
   CLOSE accountfile
END FindAccountData
I don't think theres anything wrong with the found variable as it is initialised to false and the statement "WHILE NOT found" is equivalent to "WHILE found = false". Therefore the assigning it to true short circuits the loop when the correct accountNumber is found. Nothing wrong with that

If u wanted to get picky u could say the indentation of the if statement (e.g. the THEN and else and stuff) but thats not realllllyy an error.

Besides it says "There is an error in the algorithm. Describe the error" as in error not errors as in ONE error.
 

Terlob

Member
Joined
May 6, 2007
Messages
164
Location
Wagga Wagga
Gender
Male
HSC
2008
I had that it had an infinite loop if the correct accountNumber wasnt found. That is if

Code:
IF accountFile.accountNumber = accountNumber
Is never met, than the flag will never be set to true and it will keep looping through forever. I could be wrong as though :p
 

witide

Member
Joined
Jan 31, 2008
Messages
439
Gender
Male
HSC
2008
I commented on the syntax error of the IF..THEN..ELSE, and also added that there was a possibility of an infinite loop.
 

sdsdsdsdsd

Member
Joined
Dec 2, 2007
Messages
108
Gender
Undisclosed
HSC
1998
I didn't put that but yeah I am sure that's what it's going to be, it should check if the end of file had been reached or if READ failed.
 

whitey9999

New Member
Joined
Aug 14, 2007
Messages
26
Gender
Male
HSC
N/A
I wrote down the " WHILE NOT false " didnt think it was proper syntax coz you cant really do that. even if it is a boolean
 

i4gotmypass

New Member
Joined
Sep 21, 2008
Messages
5
Gender
Male
HSC
2008
Terlob said:
I had that it had an infinite loop if the correct accountNumber wasnt found. That is if

Code:
IF accountFile.accountNumber = accountNumber
Is never met, than the flag will never be set to true and it will keep looping through forever. I could be wrong as though :p
i put this.

the algorithm is just designed to read accountFiles forever until it finds a match so if one isn't found, the algorithm is stuck in that loop.
 

fishbulb

Member
Joined
Oct 27, 2007
Messages
84
Location
Kellyville
Gender
Male
HSC
2008
I wrote that its a logic error and the program is stuck in an infinite loop because it is reading the same accountFile continuosly. It does not even stop when there are no more accountfiles to read.

But i didnt mention the "WHILE NOT found" should be "WHILE found = False".

In part iii) I did not fix the error as that was not what the question was asking.
I just added:
If found = true then
PRINT accountName
PRINT accountAddress
End If
 

darcys22

New Member
Joined
Dec 8, 2007
Messages
8
Gender
Male
HSC
2008
Found is a boolean value, if NOT Found means if Found = 0, The infinite loop is what i put.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top