Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Adding numbers binded as one interger
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
chrispaks




PostPosted: 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
Sponsor
sponsor
Martin




PostPosted: 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




PostPosted: Mon Apr 18, 2005 3:15 pm   Post subject: (No subject)

Thanks Razz
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




PostPosted: Mon Apr 18, 2005 3:18 pm   Post subject: (No subject)

Are you familiar with for loops? i is simply a counter.
chrispaks




PostPosted: 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




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: