Computer Science Canada

turing help - outputting numbers

Author:  genie [ Tue Jan 06, 2004 8:13 pm ]
Post subject:  turing help - outputting numbers

Hi, i'm doing this assignment, where its a maintenance, payroll program. the user has a menu and one field is employee number. the number has to be a 5 digit number, but if the user enters 12 it needs to output 00012 in the space. how do i get the extra zeros??? i am doing a function that will go to where it's being inputed, check to make sure its 5 or less numbers and then result it back to the main program, but how do i change it to a five digit number with the zeros to be the result??? please help!! thanks

Author:  Thuged_Out_G [ Tue Jan 06, 2004 8:26 pm ]
Post subject: 

result "000", number

Author:  AsianSensation [ Tue Jan 06, 2004 9:15 pm ]
Post subject: 

you can always use the intstr and strint convert the number back and forth from strings.

here:
code:

var num : int
var strnum : string

get num
strnum := intstr (num)

if 5 - length (intstr (num)) > 0 then
    for rep : 1 .. 5 - length (intstr (num))
        strnum := "0" + strnum
    end for
    put strnum
end if


: