Pascal parallel array help showing the values

October 30, 2010 at 09:40:15
Specs: Windows 7
I need to displays the values of my array but say someone deleted a value of the array so it was for example: array[1] is 2 and array[2] is 0 and array[3] is 5, I need to display the data like this
1. 2
2. 5
So it completely ignores the 0 and moves all the values down one, also im using parallel arrays where two of them are strings.

If any could be help it would be great, thanks!

See More: Pascal parallel array help showing the values

Report •

October 31, 2010 at 07:37:07
Maybe I can give you the code to display your array ignoring items with zero, but I don't understand the issue related to "parallel arrays" since in your example that doesn't show at all.

Waiting for more detailed info (I know well Pascal language).

Report •

October 31, 2010 at 11:03:45
Parallel arrays meaning 3 different arrays which I display together to show a group of data

For example: writeln(loop,'. ',name[loop],',',age[loop],',',food[loop]);

Will display the values together which will then mean something to the user,

Report •

October 31, 2010 at 13:16:08
Well, in my next post you'll find the sample code you requested built on your example.

Report •

Related Solutions

October 31, 2010 at 14:38:19
Here a sample code to show what you have to do. First of all notice the arrays must be initialized to null strings ('') or zero (0) since the value assigned by compiling to a variable is unpredictable.

Then you have to define two index variables one , index, to browse the arrays, the other, loop, must be incremented only if the item has its own value.

In my sample code I check for the presence of name and age, but choose your own
preferred condition.

Do you get who is item #9? The program works fine under my XP SP3, report if anything is not clear or goes wrong.

Program SAMPLE;

  loop, index: integer;
  age: array[1..10] of integer;
  name, food: array[1..10] of string;


for index:= 1 to 10 do begin
  name[index]:= '';
  food[index]:= '';
  age[index]:= 0

name[1]:= 'Liz Ashley';         age[1]:= 16;  food[1]:= 'American Pie';
name[2]:= 'Mike Gordon';        age[2]:= 14;  food[2]:= 'Corn Flakes';
name[3]:= 'Jerry Collins';
name[4]:= 'Tina Selleck';        age[4]:= 15;  food[4]:= 'Ice Cream';
name[5]:= 'John Castle';        age[5]:= 21;
name[9]:= 'Ivo Luigi Bertani';  age[9]:= 60;  food[9]:= 'Pizza';

loop:= 1;
for index:= 1 to 10 do begin
  if (age[index] <> 0) and (name[index] <> '') then begin
    WriteLn (loop, '. ', name[index],', ', age[index],', ', food[index]);
    loop:= loop + 1

Report •

Ask Question