Find Maximum Algorithm
Posted: Thu Feb 17, 2011 3:09 pm
Hi,
I am trying to implement a simple algorithm in LiveCode. The algorithm is Find Maximum.
In COMAL it is successfully implemented as:
PROC highest_clock_speed (REF clock_speed (), REF product_names$ (), items%)
max% := 0
position% := 0
PRINT
PRINT
PRINT "Option 2...FIND FASTEST CARD"
PRINT "============================"
max% := 0
FOR loop% := 1 TO items% DO
IF clock_speed (loop%) > max% THEN
max% := clock_speed (loop%)
position% := loop%
ENDIF
NEXT loop%
PRINT "The card with the highest clock speed is the "; product_names$ (position%); " with a clock speed of "; clock_speed (position%); " MHz."
ENDPROC highest_clock_speed
-------
Here is what I have so far in LiveCode:
// allow access to global arrays and variables set up in main card.
global arrayPercentageMark
global arrayName
global MaxStudents
// set up local variables
local StudentCount
local MaxMark
local position
// zero number of counter variables
put 0 into StudentCount
put 0 into MaxMark
put 0 into position
// find the student with the highest mark
repeat with loop = 1 to MaxStudents
IF arrayPercentageMark[loop] > MaxMark then
add 1 to StudentCount
put MaxMark into arrayPercentageMark[loop]
put position into loop
End if
end repeat
put "The student with the highest percentage is: " & arrayName[position] into line 7 of field output
Doesn't seem to be working, probably because I have done something stupid!
Can anyone help?
Regards,
Steven
I am trying to implement a simple algorithm in LiveCode. The algorithm is Find Maximum.
In COMAL it is successfully implemented as:
PROC highest_clock_speed (REF clock_speed (), REF product_names$ (), items%)
max% := 0
position% := 0
PRINT "Option 2...FIND FASTEST CARD"
PRINT "============================"
max% := 0
FOR loop% := 1 TO items% DO
IF clock_speed (loop%) > max% THEN
max% := clock_speed (loop%)
position% := loop%
ENDIF
NEXT loop%
PRINT "The card with the highest clock speed is the "; product_names$ (position%); " with a clock speed of "; clock_speed (position%); " MHz."
ENDPROC highest_clock_speed
-------
Here is what I have so far in LiveCode:
// allow access to global arrays and variables set up in main card.
global arrayPercentageMark
global arrayName
global MaxStudents
// set up local variables
local StudentCount
local MaxMark
local position
// zero number of counter variables
put 0 into StudentCount
put 0 into MaxMark
put 0 into position
// find the student with the highest mark
repeat with loop = 1 to MaxStudents
IF arrayPercentageMark[loop] > MaxMark then
add 1 to StudentCount
put MaxMark into arrayPercentageMark[loop]
put position into loop
End if
end repeat
put "The student with the highest percentage is: " & arrayName[position] into line 7 of field output
Doesn't seem to be working, probably because I have done something stupid!
Can anyone help?
Regards,
Steven
