code for another table

name1 = Mark, name2 = Herman, name3 = Claudia; wt1 = 153, wt2 = 87, wt3= 136; age1 = 21, age2 = 9, age3 = 20 This all needs to go into a table like this:

Name      Weight    Age
Mark         153      21
Herman        87       9
Claudia      136      20

I've done this so far:

program Table;
var name1, name2, name3,: string
     wt1, wt2, wt3:integer
      age1, age2, age3: integer

begin
 writeln('Name', 'Weight', 'Age':10);
 writeln(name1:4, wt1:10, age1:10);
 writeln(name2:4, wt2:10, age2:10);
 writeln(name3:4, wt3:10, age3:10);

I know you do something like subtracting how many letters in the word from 10, right? The book only gives two columned tables.
kazooie21Asked:
Who is Participating?
 
BatalfConnect With a Mentor Commented:
See comment
0
 
kazooie21Author Commented:
the number in the weight column should be right-aligned under the 't', the numbers in the age column should be right-aligned under the 'e' and the names in the name column should be left-aligned under the 'n' I hope that made some sense!
0
 
BatalfCommented:
program Table;
var name1, name2, name3,: string
     wt1, wt2, wt3:integer
      age1, age2, age3: integer

begin
 write(name1);
 for i:=1 to 20-length(name1) do
 write(' ');
 write(wt1);
 for i:=1 to 10-length(wt1) do
 write(' ');
 write(age1);
(* Do like this for all of the names
If you have an array it could be easier to do this*)

end;

0
 
BatalfCommented:
If name1 have a size of 13 the
for i:=1 to 20-length(name1) adds
7 <spaces>.

Instead of the code above, you could also use :

for i:=1 to 20-length(name1) do
   name1:=name1+' ';

0
 
BatalfCommented:
Some corrections :


program Table;
var name1, name2, name3,: string
     wt1, wt2, wt3:integer
      age1, age2, age3: integer ;
      tempstring : string;

begin
 write(name1);
 for i:=1 to 20-length(name1) do
 write(' ');
 str(wt1,tempstring);
 for i:=1 to 3-length(tempstring) do
 write(' ');
 write(wt1);
 for i:=1 to 10-length(wt1) do
 write(' ');
 str(age1,tempstring);
for i:=1 to 3-length(tempstring) do
 write(' ');
  write(age1);

end;


0
All Courses

From novice to tech pro — start learning today.