14 replies to this topic

#1 sharf

sharf

A tape worm is not a gift

• GMC Member
• 405 posts
• Version:GM:Studio

Posted 28 February 2008 - 07:22 PM

Ok, I want to add variables but not like

number1 + number2

number1=2, umber2=4

that would result with me getting 6
I want it to add them and be 24 like a calculator so it will add them like this
number1,number2
so it will be
2,4
24

Thanks, sharf
• 0

Xtreme Gamers Ltd.

• New Member
• 1333 posts

Posted 28 February 2008 - 07:30 PM

Edited by Renegade605, 28 February 2008 - 11:23 PM.

• 0

#3 sharf

sharf

A tape worm is not a gift

• GMC Member
• 405 posts
• Version:GM:Studio

Posted 28 February 2008 - 07:31 PM

Thanks for not reading my post I want it to add them so num1+num2 would be 59 not 14

Like a calculator adds them out as you type/push buttons.
• 0

#4 Rick_Slick

Rick_Slick

GMC Member

• New Member
• 876 posts

Posted 28 February 2008 - 07:36 PM

<{POST_SNAPBACK}>

To the original poster... your 2 is the ten's digit, so multiply it by 10 and then add it to your 4 to get 24.

num1 = 2
num2 = 4

So you would want: (num1 * 10) + num2

num1 = 2
num2 = 4
num3 = 1

and wanted to get 241 out of it, then you would do: (num1 * 100) + (num2 * 10) + num3
• 0

#5 zorblood

zorblood

GMC Member

• New Member
• 177 posts

Posted 28 February 2008 - 07:37 PM

a calculator does not do that... thats not even math. You could try using their strings and combine them.
• 0

#6 sharf

sharf

A tape worm is not a gift

• GMC Member
• 405 posts
• Version:GM:Studio

Posted 28 February 2008 - 07:44 PM

Thanks, I'm making a calculator, and I had a calctxt as the variable. I want it so when you hit the number it adds it before the previous number....like a real calculator.

Any help?
• 0

#7 Rick_Slick

Rick_Slick

GMC Member

• New Member
• 876 posts

Posted 28 February 2008 - 07:59 PM

num1 = the current number on the calculator display

num2 = the number to add

multiply num1 by 10, then add num2

for instance:

You want to press a 5 so the calculator will display: 5145

num1 = 514

num2 = 5

(num1 * 10) + num2 = 5145
• 0

#8 sharf

sharf

A tape worm is not a gift

• GMC Member
• 405 posts
• Version:GM:Studio

Posted 28 February 2008 - 08:04 PM

yes but that can get really tedious when adding large amounts....
• 0

#9 Falcondude

Falcondude

GMC Member

• New Member
• 50 posts

Posted 28 February 2008 - 08:08 PM

Mess around with strings. string(num1) and string_insert(blah blah blah num2) should work.
• 0

#10 Rick_Slick

Rick_Slick

GMC Member

• New Member
• 876 posts

Posted 28 February 2008 - 08:09 PM

All you're doing is multiplying the current display number by 10 and then adding the number that the user presses on the calculator. Two steps every time someone presses a number key. How is that tedious?

You can change the current display number to a string and change the number that the user presses to a string, and just concatenate them together, I guess. But that's no more or less tedious. Plus you'd have to re-convert them back into values to perform any mathematical operations on them.
• 0

#11 Dangerous_Dave

Dangerous_Dave

GMC Member

• Global Moderators
• 9384 posts
• Version:Unknown

Posted 28 February 2008 - 08:12 PM

num1="5";
num2="8";

num1+num2= "58";
• 0

#12 Falcondude

Falcondude

GMC Member

• New Member
• 50 posts

Posted 28 February 2008 - 08:12 PM

Plus you'd have to re-convert them back into values to perform any mathematical operations on them.

real(num3);

Seems pretty simple to me.
• 0

#13 Twigster_TF

Twigster_TF

GMC Member

• New Member
• 62 posts

Posted 28 February 2008 - 08:16 PM

ok, the easiest way to do it is to have calctext as a string

ie:

calctext = "567"

when the button is pressed (ie 5):

calctext = calctext + "5"

calctext now equals "5675"

to use it as a number, ie for adding, use: real(calctext)
• 0

#14 sharf

sharf

A tape worm is not a gift

• GMC Member
• 405 posts
• Version:GM:Studio

Posted 28 February 2008 - 08:19 PM

thanks Twigster_TF thats the kind of thing Im looking for... the only thing, is it possible to make a string, and then just have a variable equal that string?
• 0

#15 Rick_Slick

Rick_Slick

GMC Member

• New Member
• 876 posts

Posted 28 February 2008 - 08:19 PM

If real(string(num1) + string(num2)) is simpler than (num1 * 10) + num2, then so be it.

Also, if you press CLEAR on your calculator and want to clear the most recently added number, then newnumber = floor(oldnumber/10).
• 0

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users