i have been given a so called simple equation to solve

but if this is a simple equation after only 5 months of

programming then god knows what the next 4 years

is going to bring

i am to design a program that will ask the user to enter

any number of columns and any number of rows

given that the columns and rows are of equal height and length

the program will then calculate how many vertical and horizontal

lines a {secondary line would pass through if drawn from the top

left hand column to the bottom right hand column} alright that might

sound simple enough but heres the tricky part if the secondary line

passes directly through a corner of a box then you cannot count it as

passing through 2 lines vertical and horizontal but only 1 line

example is if the user inputs 1 column and 1 row a secondary

line passing from corner to corner would not pass through any

vertical or horizontal lines so the value would be zero if however

the user inputs 2 columns and 1 row the secondary line would

pass through 1 vertical line giving total value as 1

if 2 coloumns and 2 rows where inputted then the value would still

be 1 because the secondary line passes directly through a corner of a box

so this where i need the help i need the formula to into my procedure to

calculate the correct number of lines the secondary line will pass through

my program goes like this

program passing_through;

uses wincrt;

var

columns, rows : integer;

procedure get_numbers;

begin

writeln (‘ enter the number of columns and rows’);

readln (columns,rows);

if columns > 1

then

columns := columns + 1;

if rows > 1

then

rows := rows + 1;

end;

procedure calculate_lines;

var

total : integer;

begin

{formula required}

writeln (‘the number of lines is',total);

end;

begin

get_numbers;

calculate_lines

end.

as i think this formula is going to take some working out

i think 150 points will be a hard earned 150 points

cheers gandalph

{ I don't know why you have added 1 in rows and columns }

program passing_through;

uses crt;

var

columns, rows : integer;

procedure get_numbers;

begin

write('Enter the number of columns and rows : ');

readln (columns,rows);

if columns > 1

then

columns := columns + 1;

if rows > 1

then

rows := rows + 1;

end;

procedure calculate_lines;

var

total : integer;

true,false,cornercut : integer;

begin

true := 1;

false := 0;

cornercut := -1;

columns := columns - 1;

rows := rows - 1;

if rows=columns then total := columns - 1

else if odd(columns) AND odd(rows) then cornercut := false

else if odd(columns) AND NOT odd(rows) then cornercut := false

else if NOT odd(columns) AND odd(rows) then cornercut := false

else if NOT odd(columns) AND NOT odd(rows) then cornercut := true;

if cornercut=true then

begin

if (columns > rows) then

cornercut := (columns MOD rows) - 1

else if (rows > columns) then

cornercut := (rows MOD columns) - 1;

total := (columns-1)+(rows-1)-corne

writeln ('The number of lines is = ',total);

end;

if cornercut=false then

begin

total := (columns-1)+(rows-1);

writeln ('The number of lines is = ',total);

end;

if (rows = columns) then writeln ('The number of lines is = ',total);

end;

begin

get_numbers;

calculate_lines;

readln;

end.