Computer Science Canada

Issue with character replacement in a string

Author:  adriian [ Sun Jan 13, 2019 4:39 pm ]
Post subject:  Issue with character replacement in a string

What is it you are trying to achieve?
I'm trying to replace a character in the variable "guess" with the variable "letter" at any given position (i) if the letter is in the variable "word".


What is the problem you are having?
I am getting the error "Left side of assignment is not a variable and hence cannot be assigned to." Except "guess" IS a variable.


Describe what you have tried to solve this problem
I tried searching it up online but couldn't find anything useful.


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

Turing:


put "Enter the word to guess: "
get word
loop

    exit when (guess = word)

    put "Enter a letter to guess: "
    get letter

    for i : 1 .. length (word)
        if letter = word (i) then
            guess(i) := letter
        elsif letter not= word (i) then
            guess(i) := "-"
        end if
    end for
    put guess
end loop


Please specify what version of Turing you are using
4.1.1

*NOTE: Yes I did initialize the variables above, I just didn't include them in the post. They're strings and they have been set to "'.

Author:  Insectoid [ Mon Jan 14, 2019 9:41 am ]
Post subject:  RE:Issue with character replacement in a string

guess may be a variable but guess(i) is not a variable. There is a simple way around this.

Author:  adriian [ Mon Jan 14, 2019 12:41 pm ]
Post subject:  Re: RE:Issue with character replacement in a string

Insectoid @ Mon Jan 14, 2019 9:41 am wrote:
guess may be a variable but guess(i) is not a variable. There is a simple way around this.

Can you give me a hint or point me in the right direction of this?

Author:  Insectoid [ Tue Jan 15, 2019 12:18 am ]
Post subject:  RE:Issue with character replacement in a string

I may have literally stated the solution earlier in this thread.

Author:  adriian [ Tue Jan 15, 2019 2:08 pm ]
Post subject:  Re: RE:Issue with character replacement in a string

Insectoid @ Tue Jan 15, 2019 12:18 am wrote:
I may have literally stated the solution earlier in this thread.

All you said was guess(i) is not a variable. I'll literally pay you like 10 dollars if you can tell me how to do this. You're saying it's so simple but I have no idea what to do

Author:  Insectoid [ Tue Jan 15, 2019 10:11 pm ]
Post subject:  RE:Issue with character replacement in a string

I also responded in the other thread you posted. I just checked, it's there.


: