Help with a program/arrays? - Programmers Heaven

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# Help with a program/arrays?

Posts: 2Member
Hey,
I have to write a program for school which calculates the fibonacci sequence with two inputted integers, but I have to use an array and procedures in order to do it.

I think my problem is probably that I don't understand arrays properly as we've recently done them, but I can't find what's wrong with my code. It runs and the inputs/close programs work okay but it doesn't do the sequences - it just comes up with a large number every time that's like 4 hundred thousand something.

Does anybody have any idea what I could be doing wrong? Here is my code:

Thanks

• Hollywood, FlPosts: 26Member
I did what I could to get your program running. I commented out lines that either are not needed or need to be changed. I tried a few numbers and it seems to do the job.
[code]program ex27;

uses
sysutils;
var
numbers:array [1..2] of integer;
loopcounter, loopcounter1, i, loopcounter2, startat, answer, dummy : integer;
valid: boolean;
input : string;

procedure getinput; //WORKS
begin
//initialise
for i := 1 to 2 do
numbers[i]:= 0;

for loopcounter1:=1 to 2 do
begin
repeat
valid:=true;

if length(input)=0 then
valid:=false
else
begin
if input[1]='-' then
startat:=2
else
startat:=1;

for loopcounter2:=startat to length(input) do
begin
if not (input[loopcounter2] in ['0'..'9']) then
valid:=false;
break;
end;
end;
if not valid then
writeln('this is not a valid integer.');
until valid;
numbers[loopcounter1]:=strtoint(input);
end;
end;
(* procedure calculatefibonacci(numbers: array of integer); *)
procedure calculatefibonacci;
begin
(* for loopcounter:=1 to 2 do
dummy:=numbers[1]+numbers[2];
write(numbers[2]);
begin *)
writeln;
(* end; *)
end;
procedure closeprogram;
begin
write('Press enter to close');