Hi,

I am trying to create a program that stores employee records in an array, and also has the option to delete records and view various details.

I am trying to create a menu so that when you choose an option the request will be carried out, the problem I have is that I have a option that allows me to add a new employee to my array, but every time I select the option and enter the new employee details it keeps overriding the information stored in the 1st array position , instead of adding the new employee details into the next array position so I can not have more than 1 record when I should be able to store 10.

Any help would be very much appreciated as I feel like I have been banging my head against a wall for the last 2 days.

My code so far is:
attached

you know bro you'd probably gotten an answer if you'd jst put da code with ur post....anyways ur problem should be a simple logical error within the procedure that you made to add items to the record ;)
next time post the code lol

Ihave attached the code on the attachment, is there another way to attach it?

copy paste it and put it between tags(without da quotes) ;)
makes stuff easier,ppl are jst too lazy or too busy to stop and download an attachment no matter how small it maybe :)

This is my program so far, can you explain what you mean, currently it keeps overwriting my record and will only store data in my first array position.

Thanks


program employee;

{$APPTYPE CONSOLE}

uses
SysUtils;

const
Capacity = 4;

type
EmployeeRec = record
Firstname, Surname, Department:string;
Extnumber:integer;
end;

type
WorkT = array[0..capacity-1] of EmployeeRec;

Procedure addEmployee( position:integer;var employee:WorkT);

var
size:integer;


begin

size:=0;


begin
inc(position);
write('firstname:');
readln (employee.firstname);
write('surname:');
readln(employee.surname);
write('department:');
readln(employee.department);
write('Extension Number:');
readln(employee.Extnumber);
writeln;


while (employee.extnumber <1000) or (employee.extnumber >5999)
do
begin
writeln('extension number has to be in the range of 1000-5999');
readln(employee.extnumber);

end;

end;
end;


procedure ListNames(employee:workT);

var
counter:integer;

begin
counter:=0;

write(employee[counter].firstname );
write(' ');
write(employee[counter].surname );
write(' ');
write(employee[counter].department );
write(' ');
write(employee[counter].extnumber);
writeln;

end;

procedure menu(var choice:integer);

begin

writeln('1. Add employee');
writeln('2. Delete employee');
writeln('3. List all employees');
writeln('4. List all employees in a department');
writeln('5. Find the phone number for an employee');
writeln('6. Quit');
readln(choice);

end;


var
employee:workT;
choice:integer;
position:integer;


begin

position:=0;
writeln('Welcome to the employees database');
writeln;

repeat
menu(choice);

case choice of
1: addemployee(position, employee);
3: ListNames(employee)

else
writeln('Error, please select a correct option');
writeln;
end

until choice =6;


end.

if this is ur exact code then there's a flaw,you don't have a loop with da size variable inside that procedure.so in other words it always writes to da 0 position of da array...

I have tried it with a loop and when I select the option then it will not let me enter one record, it makes me enter the record, how ever many times I have the loop running for.
What I am trying to achieve is when I select the option to add a record then it allows me to enter one record and then gives me the menu again to make another choice and also allocates that record to an array postion. if I then choose to add another record then it will then allow me to put my next record in the next available array space etc etc.. The menu will then be displayed and I can make another selection eg. display records.. Once that procedure is carried out the menu is then displayed and if I choose to add another record the first 2 array positions already have records in, so my next record will go in position 3. Does this make any sense?

Thanks for the help anyway..

use a boolean variable with that loop to give da user a choice to continue adding records or to quite..That should do da trick
ima try out this code myself lol

ok scrap that jst use a char wiv it
here's a rough pseudocode

begin
counter variable:=1or0
char variable:='y' 
while (counter logic) AND (char_variable<>n) do
begin
bla
bla
bla
counter:=counter+1
write('continue or wuteva [Y/N]')
read char variable {it'd be a good idea to use a if statement to make sure da input is limited to those two letters}
end.

The problem is here: Procedure addEmployee( position:integer;var employee:WorkT); and here: 1: addemployee(position, employee); The addEmployee procedure increments its local position variable, but it does not change the global position variable. There are two ways to fix this:

1. Procedure addEmployee( [B]var[/B] position:integer;var employee:WorkT); 2.

1: begin
   inc( position );
   addEmployee( position, employee )
   end;

Hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.