clsyorkshire
Programmer
Hi, I'm making a program where items of stock can be added to a data file, and then I need another program that will display all the data in the file. I've started making the program to read the data but my problem is it only allows storage for one set of data. Heres what I have so far (below), any help would be appreciated:
Program one;
Uses crt;
TYPE
recs=record
code:string[8]; {number in square brackets = number of characters}
itemname:string[30];
costprice:real;
saleprice:real;
end;
VAR
stockfile:file of recs;
temp:recs;
filename:string[12];
answer:char;
BEGIN
clrscr; {clears the screen}
gotoxy(5,2);
textcolor(white);
writeln('Please enter the name of the file to create : ');
textcolor(yellow);
gotoxy(51,2);
readln(filename);
assign(stockfile,filename);
rewrite(stockfile);
REPEAT
textcolor(white);
gotoxy(22,5);
writeln('Please enter the item code : ');
textcolor(yellow);
gotoxy(51,5);
readln(temp.code);
textcolor(white);
gotoxy(22,8);
writeln('Please enter the item name : ');
textcolor(yellow);
gotoxy(51,8);
readln(temp.itemname);
textcolor(white);
gotoxy(21,11);
writeln('Please enter the cost price : ');
textcolor(yellow);
gotoxy(51,11);
readln(temp.costprice);
textcolor(white);
gotoxy(22,14);
writeln('and finally the sale price : ');
textcolor(yellow);
gotoxy(51,14);
readln(temp.saleprice);
write(stockfile,temp);
textcolor(cyan);
gotoxy(20,20);
writeln('Do you want to enter another?');
gotoxy(51,20);
textcolor(yellow);
readln(answer);
clrscr;
UNTIL upcase(answer)='N';
Close(stockfile);
END.
Program one;
Uses crt;
TYPE
recs=record
code:string[8]; {number in square brackets = number of characters}
itemname:string[30];
costprice:real;
saleprice:real;
end;
VAR
stockfile:file of recs;
temp:recs;
filename:string[12];
answer:char;
BEGIN
clrscr; {clears the screen}
gotoxy(5,2);
textcolor(white);
writeln('Please enter the name of the file to create : ');
textcolor(yellow);
gotoxy(51,2);
readln(filename);
assign(stockfile,filename);
rewrite(stockfile);
REPEAT
textcolor(white);
gotoxy(22,5);
writeln('Please enter the item code : ');
textcolor(yellow);
gotoxy(51,5);
readln(temp.code);
textcolor(white);
gotoxy(22,8);
writeln('Please enter the item name : ');
textcolor(yellow);
gotoxy(51,8);
readln(temp.itemname);
textcolor(white);
gotoxy(21,11);
writeln('Please enter the cost price : ');
textcolor(yellow);
gotoxy(51,11);
readln(temp.costprice);
textcolor(white);
gotoxy(22,14);
writeln('and finally the sale price : ');
textcolor(yellow);
gotoxy(51,14);
readln(temp.saleprice);
write(stockfile,temp);
textcolor(cyan);
gotoxy(20,20);
writeln('Do you want to enter another?');
gotoxy(51,20);
textcolor(yellow);
readln(answer);
clrscr;
UNTIL upcase(answer)='N';
Close(stockfile);
END.