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

Username:   Password: 
 RegisterRegister   
 Need Help! > Bar Code Program
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
methodman




PostPosted: Sun Sep 15, 2002 1:05 pm   Post subject: Need Help! > Bar Code Program

I have to create a bar code program for school. I just wanted to find out how to split a 12 digit number (eg: 125545697547) into 'odd' (154674) and 'even' (255957) positions and store it in a variable. After the user inputs that number because calculations have to be done to the 'odd' and 'even' position numbers.

Any help is appreciated! Thanks! Very Happy
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sun Sep 15, 2002 1:47 pm   Post subject: bar code

What you do is you run a for loop from 1 to 12 and see if the number is even or odd, then add it to the appropriate variable.

code:

const number : string := "123456789123"
var even : string :=""
var odd : string :=""

for i:1..12
if strint(number(i)) rem 2 = 1
then %number is odd
odd := odd + number(i)
else %number is even
even := even + number(i)
end if
end for

put odd
put even


Let me explain "if strint(number(i)) rem 2 = 1" in deapth.

strint converts a string value to interger value
number(i) is the position i value of number constant
rem 2 is remeinder when the number is devided by 2 which shows if the number is even or odd. If remeinder is 1, then its odd, otherwise it's even.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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  [ 2 Posts ]
Jump to:   


Style:  
Search: