This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Rangicus's profile picture

[SOLVED]Unexpected Symbol

Started by Rangicus, 04 September 2012 - 01:30 AM
Rangicus #1
Posted 04 September 2012 - 03:30 AM
I am trying to write a calculator code and I am making the addition portion of the code, and I keep getting this error.

bios:206: [string "calc"]:13: unexpected symbol
Which is weird considering on line 13 of my "calc" code there are no unexpected symbols (as far as I know), this is my code.

operation = nil
variable1 = nil
variable2 = nil
print("What operation would you like to use?")
operation = io.read()
print("What is the first number in which to use?")
variable1 = io.read()
print("The second number?")
print("Processing...")
tonumber(variable1)
tonumber(variable2)
if "..operation.." == "addition" then
"..variable1.." + "..variable2.."
end

NIN3 #2
Posted 04 September 2012 - 03:49 AM
I am trying to write a calculator code and I am making the addition portion of the code, and I keep getting this error.

bios:206: [string "calc"]:13: unexpected symbol
Which is weird considering on line 13 of my "calc" code there are no unexpected symbols (as far as I know), this is my code.

operation = nil
variable1 = nil
variable2 = nil
print("What operation would you like to use?")
operation = io.read()
print("What is the first number in which to use?")
variable1 = io.read()
print("The second number?")
print("Processing...")
tonumber(variable1)
tonumber(variable2)
if "..operation.." == "addition" then
"..variable1.." + "..variable2.."
end

I think you need to cut some of the ".." stuff. so


if operation == addition then
variable1 + variable2
end

I could be wrong, and what I would do instead for that is


if operation==addition then
answer=variable1 + variable2
end
print(anwser)

also, it never collects the second number….
EDIT:fixed spelling in last one…
Rangicus #3
Posted 04 September 2012 - 04:00 AM
I am trying to write a calculator code and I am making the addition portion of the code, and I keep getting this error.

bios:206: [string "calc"]:13: unexpected symbol
Which is weird considering on line 13 of my "calc" code there are no unexpected symbols (as far as I know), this is my code.

operation = nil
variable1 = nil
variable2 = nil
print("What operation would you like to use?")
operation = io.read()
print("What is the first number in which to use?")
variable1 = io.read()
print("The second number?")
print("Processing...")
tonumber(variable1)
tonumber(variable2)
if "..operation.." == "addition" then
"..variable1.." + "..variable2.."
end

I think you need to cut some of the ".." stuff. so


if operation == addition then
variable1 + variable2
end

I could be wrong, and what I would do instead for that is


if operation==addition then
answer=variable1 + variable2
end
print(anwser)

also, it never collects the second number….
EDIT:fixed spelling in last one…
So I turned this

operation = nil
variable1 = nil
variable2 = nil
print("What operation would you like to use?")
operation = io.read()
print("What is the first number in which to use?")
variable1 = io.read()
print("The second number?")
print("Processing...")
tonumber(variable1)
tonumber(variable2)
if "..operation.." == "addition" then
"..variable1.." + "..variable2.."
end
Into this based upon what you said

operation = nil
variable1 = nil
variable2 = nil
answer = nil
print("What operation would you like to use?")
operation = io.read()
print("What is the first number in which to use?")
variable1 = io.read()
print("The second number?")
print("Processing...")
tonumber(variable1)
tonumber(variable2)
if operation == "addition" then
variable1 + variable2 = answer
end

and I got this

bios:206: [string "calc"]:14: '=' expected
So I thought about adding another '=' so it said '==' but I got the same error
NIN3 #4
Posted 04 September 2012 - 04:03 AM
First off, I do think that answer= needs to be first, not last. when its that way, it sets the variable "answer" to var1 plus var2.

And you still dont set variable 2. you should put in

print"The second number?"
variable2=read()
print("Processing...")
Rangicus #5
Posted 04 September 2012 - 04:46 AM
http://www.computercraft.info/forums2/index.php?/topic/3853-then-expected/
Could you help me with this one also?