Forum > Beginners

Problem with Arrays

(1/2) > >>

IAmTheLaw:
Hello, i need help with a simple program about arrays, my goal is to obtain an arrangement like a matrix, but im having problems with the jump line, because i only get the result in one line, this is what i've got:

program project1;

uses
  crt;

const
  L=5;

var
  T: array[1..L,1..L] of real;
  n: real;
  i,j: integer;

begin
  write('write a number ');readln(n);
  begin
  For i:=1 to L do
   begin
    For j:=1 to L do
     begin
      T[i,j]:= n;
      write(i,',',j,' ',T[i,j]*i*j:0:2,' ');
     end;
   end;
  end;
  readln;
end.

but if i add a 'writeln' between the 'for' cicles it only shows me the las line of the array (5,1 to 5,5) but does not show me the other and i have no idea why it does do this, anyone can help me?

engkin:
Did you try to add WriteLn after the inner loop? Like this:

--- Code: ---program project1;

uses
  crt;

const
  L=5;

var
  T: array[1..L,1..L] of real;
  n: real;
  i,j: integer;

begin
  write('write a number ');readln(n);
  begin
  For i:=1 to L do
   begin
    For j:=1 to L do
     begin
      T[i,j]:= n;
      write(i,',',j,' ',T[i,j]*i*j:0:2,' ');
     end;
    WriteLn;  //<---- This?
   end;
  end;
  readln;
end.

--- End code ---

Tomas Hajny:
If the assumption mentioned in the previous post is correct (i.e. you tried adding WriteLn at the suggested place and it didn't work as expected), it might be useful to mention your platform and used compiler version in order to check if you didn't encounter some bug specific to a certain platform specific implementation of unit Crt (possibly also related to a particular older version, although I'm not immediately aware of a similar bug fixed in previous versions).

IAmTheLaw:

--- Quote from: Tomas Hajny on April 24, 2014, 08:58:56 am ---If the assumption mentioned in the previous post is correct (i.e. you tried adding WriteLn at the suggested place and it didn't work as expected), it might be useful to mention your platform and used compiler version in order to check if you didn't encounter some bug specific to a certain platform specific implementation of unit Crt (possibly also related to a particular older version, although I'm not immediately aware of a similar bug fixed in previous versions).

--- End quote ---

I've tried what engkin said but its the same, it only shows the last line. I'm using the lazarus v1.2.2 on windows 8.1, i add a image, hope that help.

Blaazen:
Output of engkin's version is fine here in Linux console (xterm). I have no Win, only Wine and I cannot make it work in cmd.exe, don't know why.

Navigation

[0] Message Index

[#] Next page

Go to full version