So I have run into a problem at the moment I cannot wrap my head around.
I need to find the index of the smallest number in an Array, I know in several programming languages there are functions to do this.
I thought this was quite an easy thing to do and I have done before in other languages, however I am starting to become stumped (probably just finding a downfall of pascal??).
Definitely wasn't expecting to get hung-up by this.
So below my solution was a simple conditional check within a For loop. If smaller than the variable then make the variable equal to the iteration/index.
Keep checking for smaller numbers. However, the result of oldest is always Zero even when the smallest number exists in [1].
So Process procedure decides and receives the event trigger, if a condition exists secondary procedures are executed which contain this code below.
The variable oldest is a value from 1 to 16.
Anyone have a clue as to why this may be, or have some guidance to an alternative method to perform this?
Code: Select all
oldest:=17; //Initialize for detecting oldest index
//Search for lowest number in array and purge
for k:=0 to 15 do begin
if order_array[k] < oldest then begin
oldest := k;
end;-S
