10,000 EMPLOYEES
10,000 EMPLOYEES
(OP)
HI,
i'm trying to figure out the best way to create 9999 random employees each with an employee number (0001-9999) attached to them. i think that for the purpose of what i need, it would be easier to create them with all the same name followed by their number. ie. JOHN SMITH0001,JOHN SMITH0002 etc...
any ideas for a new pascal user.
cheers
i'm trying to figure out the best way to create 9999 random employees each with an employee number (0001-9999) attached to them. i think that for the purpose of what i need, it would be easier to create them with all the same name followed by their number. ie. JOHN SMITH0001,JOHN SMITH0002 etc...
any ideas for a new pascal user.
cheers
RE: 10,000 EMPLOYEES
random(x) generates a random number in the interval [0,1,...x[ (i.e. x not included).
Use the function str to convert a number to a string:
str(125,s); => s = '125'
Use + to concatenate strings:
s:='john'+'125'; => s = 'john125'
Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
http://student.vub.ac.be/~bvingerh/
Don't worry what people think about you. They're too busy wondering what you think about them.
RE: 10,000 EMPLOYEES
when i said i was a new pascal user, i meant really new. so i dont really understand any of what you just said except for your signature (cool by the way) i'll look in some books to try and figure out what you're telling me.
regards
chriscarlile911
p.s. if, "once you pop, you can't stop", why do pringle come in a resealable tub!?!?!?
RE: 10,000 EMPLOYEES
FUNCTION generate_name(name : string; number : word) : string;
VAR number_string : string;
begin
{ convert the given number to a string: }
str(number,number_string);
{ push zeroes in front of it, so all "numbers" have the same length }
while length(number_string)<4 do
number_string:='0'+number_string;
{ return as result the concatenation of the given name and the number }
generate_name:=name+number_string;
end;
Executing generate_name('JOHN SMITH',1); will result in the value 'JOHN SMITH0001'.
The following example will print this result on screen:
VAR s : string;
BEGIN
s:=generate_name('JOHN SMITH',1);
writeln(s);
END.
If you don't understand all this code, you should really read some book on Pascal. People in this forum can only help if you already know Pascal's syntax and are at least remotely familiar with its iteration and selection techniques.
Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
http://student.vub.ac.be/~bvingerh/
Don't worry what people think about you. They're too busy wondering what you think about them.
RE: 10,000 EMPLOYEES
RE: 10,000 EMPLOYEES
Also, since he's a beginning programmer, an example of a while loop can be more helpful in learning to work in Pascal than a cryptic ':' construct.
Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
http://student.vub.ac.be/~bvingerh/
Don't worry what people think about you. They're too busy wondering what you think about them.
RE: 10,000 EMPLOYEES
The ':' thing isn't very well documented in help-files, either.
RE: 10,000 EMPLOYEES