ID:267681
 
Hi

the title says it all.

thanks
var/number = 1 + 2
Or...
var/numberA = 4
var/numberB = 6
var/numberC = numberA + numberB

Just basic math.
In response to Jon88
that helps but i dont think it worked for what i got..

this is my code how it is

mob
Login()
var/num = input("First Number?")
var/num2 = input("Second Number?")
switch(alert("[num]??[num2]",,"+","-"))
if("+")
usr << "[num]+[num2]..."
usr<<num + num2
if("-")
usr<<"[num]-[num2]"
In response to Mousie_kebabs
Putting the quotes around the variables makes it a string. Strings are text, not numbers. To be sure that what you get from your two input()s are numbers, put text2num() around them.
In response to Jon88
i didnt quite understand it.. but i tried somthing else

mob
Login()
var/numberA = input("First Number?")
var/numberB = input("Second Number?")
var/numberC = numberA + numberB
usr<<"[numberC]"

but it still did not work...i know it is somthing simple that i am missing out
In response to Mousie_kebabs
I'm pretty sure that input()s give a TEXT STRING back. IT would be the same as saying
var/number1 = "1"
var/number2 = "5"
var/number3 = number1 + number2
which would be.... 15.
What you can do however, is this:
var/numberA = text2num(input("First Number?"))
var/numberB = text2num(input("Second Number?"))
var/numberC = numberA + numberB
In response to Jon88
thanks :D

just one last thing

mob
Login()
var/numberA = text2num(input("First Number?"))
var/numberB = text2num(input("Second Number?"))
switch(alert("[numberA] ? [numberB]",,"+","-"))
if("+")
var/numberC = numberA + numberB
if("-")
var/numberC = numberA - numberB
usr<<"[numberC]"


errors:

test.dm:10:error:numberC:undefined var
test.dm:7:numberC :warning: variable defined but not used
test.dm:9:numberC :warning: variable defined but not used
In response to Mousie_kebabs
mob
Login()
var/numberA = input("First Number?") as num
var/numberB = input("Second Number?") as num
var/numberC = 0
switch(alert("[numberA] ? [numberB]",,"+","-"))
if("+")
numberC = numberA + numberB
if("-")
numberC = numberA - numberB
usr<<"[numberC]"

That code should work fine. The one you had before was poorly written. Good luck. :-)
In response to Lord of Water
Lord of Water wrote:
mob
Login()
var/numberA = input("First Number?") as num
var/numberB = input("Second Number?") as num
var/numberC = 0
switch(alert("[numberA] ? [numberB]",,"+","-"))
if("+")
numberC = numberA + numberB
if("-")
numberC = numberA - numberB
usr<<"[numberC]"

That code should work fine. The one you had before was poorly written. Good luck. :-)


thanks...it all works appeart from on bit.

the switch(alert(

it does not show up.

i removed all the <spaces> and put them with <tabs>

In response to Mousie_kebabs
Do you mean it does not show up in the editor when you paste the code from the forum, or it does not send you the alert box when you run the program?
Lots of ways to do math.

a += b
a += (b + c)
a -= b
a *= b
a /= b
a = a + b
a = (a + b + c)
a = a - b
a = a * b
a = a / b

That covers most of it. In a text string, you can also do math like this:

world << "[a + b]"
world << "[round(100 / a * b)]"
world << "[((a + b + c + d + e) * f) / g]"
In response to Lord of Water
sorry it's my fault i had the wrong code file ticked.

thanks Lord :-D