Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Need Help! > Bar Code Program
Author Message
methodman

Posted: 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!

Tony

Posted: 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.
Tony's programming blog. DWITE - a programming contest.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 2 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: