
-----------------------------------
chrispaks
Mon Apr 18, 2005 3:08 pm

Adding numbers binded as one interger
-----------------------------------
For example: if you entered 12345 into the get command area, the program will put "it is 5 numbers long and their sum is 15"

I know how to use the length command, but what command would I use to convert it into? Would I use a strint or intstr command? strintok? how would i seperate it so I can add the numbers?

-----------------------------------
Martin
Mon Apr 18, 2005 3:11 pm


-----------------------------------
var number : string := "76391"
put length (number)
var sum : int := 0
for i : 1 .. length (number)
     put "number (", i, ") = ", number (i)
     sum = sum + strint (number (i))
end for

-----------------------------------
chrispaks
Mon Apr 18, 2005 3:15 pm


-----------------------------------
Thanks :P
Now I'd just use the "put sum" to display it?

and the i is used as a variable to help add them together right?

-----------------------------------
Martin
Mon Apr 18, 2005 3:18 pm


-----------------------------------
Are you familiar with for loops? i is simply a counter.

-----------------------------------
chrispaks
Mon Apr 18, 2005 4:42 pm


-----------------------------------
no im just familiar with 'loops' in general
ill go read a guide and learn it, I dont even know much GUI im a noob at this stuff

-----------------------------------
Martin
Mon Apr 18, 2005 4:55 pm


-----------------------------------
A for loop is a counted loop.

for i : 1 .. 5
     put i, " "..
end for

is the equivalent of
var i : int := 0
loop
     i := i + 1
     put i, " "..
     if i = 5 then
          exit
     end if
end loop
