Computer Science Canada

Strangest error ever

Author:  packocrayons [ Thu Feb 28, 2013 3:23 pm ]
Post subject:  Strangest error ever

What is it you are trying to achieve?
get an answer and separate it into command and subcommand, and go to a process based on command


What is the problem you are having?
When certain subcommand and command combinations are used, an if statement isn't entered.
When "drop burger" is entered, the for loop runs twice, erroring the first time (as it should), and then doesn't enter the if statement the second time at all. the program jumps right to "Invalid command"
"drop potato" runs the for loop 3 times, working the first two and then jumping to "invalid command"
"take axe" errors, but "drop axe" does not
most other attempted "drop" commands work.
all other commands work, drop and take are the only issues as of yet


Describe what you have tried to solve this problem
I have added put statements and the delay in the loop to make it run at troubleshoot speed, I really don't know how to address the problem.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

Turing:


procedure commandcalc
    for i : 1 .. length(answer)
        put i
        put answer (i)
        delay (1000)
        if answer (i) = " " then
            command := answer (1 .. (i - 1))
            subcommand := answer ((i + 1) .. *)
            exit
        elsif answer (i) = answer (*) then
            command := answer (1 .. *)
            exit
        else
        put "Error"
        end if
    end for
    if command = "go" then
        go
    elsif command = "drop" then
        drop
    elsif command = "look" then
        look
    elsif command = "kill" then
        kill
    elsif command = "open" then
        Open
    elsif command = "close" then
        Close
    elsif command = "take" then
         take
    elsif command = "buy" then
        buy
    elsif command = "stats" then
         stats
    elsif command = "inventory" then
        inventoryProcedure
    elsif command = "list" then
        list
    else
        put "Invalid command"
        space
    end if
end commandcalc



Please specify what version of Turing you are using
Tried on both 4.1.2 and 4.1.1, using 4.1.2 now.

Author:  Dreadnought [ Thu Feb 28, 2013 3:43 pm ]
Post subject:  Re: Strangest error ever

What are you asking the program to do here?
Turing:
elsif answer (i) = answer (*) then

Author:  Nacoty [ Thu Feb 28, 2013 5:59 pm ]
Post subject:  Re: Strangest error ever

Dreadnought @ Thu Feb 28, 2013 3:43 pm wrote:
What are you asking the program to do here?
Turing:
elsif answer (i) = answer (*) then


It is checking if the letter that the for loop is currently checking is the last letter in the string. At least I'm pretty sure it is.

Author:  Dreadnought [ Fri Mar 01, 2013 11:53 am ]
Post subject:  Re: Strangest error ever

Suppose you have a sting "yolo".

clearly string(1) not= string(*)
what about string(2) and string(*)?

Author:  Nacoty [ Fri Mar 01, 2013 2:58 pm ]
Post subject:  RE:Strangest error ever

We fixed it, it's fine.


: