Computer Science Canada

Need Help! > Bar Code Program

Author:  methodman [ 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

Author:  Tony [ 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.


: