Author |
Message |
chrispaks
|
Posted: Mon Apr 18, 2005 3:08 pm Post subject: 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? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Martin
|
Posted: Mon Apr 18, 2005 3:11 pm Post subject: (No subject) |
|
|
code: | 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
|
Posted: Mon Apr 18, 2005 3:15 pm Post subject: (No subject) |
|
|
Thanks
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
|
Posted: Mon Apr 18, 2005 3:18 pm Post subject: (No subject) |
|
|
Are you familiar with for loops? i is simply a counter. |
|
|
|
|
|
chrispaks
|
Posted: Mon Apr 18, 2005 4:42 pm Post subject: (No subject) |
|
|
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
|
Posted: Mon Apr 18, 2005 4:55 pm Post subject: (No subject) |
|
|
A for loop is a counted loop.
code: | for i : 1 .. 5
put i, " "..
end for |
is the equivalent of
code: | var i : int := 0
loop
i := i + 1
put i, " "..
if i = 5 then
exit
end if
end loop |
|
|
|
|
|
|
|