#Delphi

23 messages · Page 1 of 1 (latest)

mellow venture
#

I dont know where i went wrong
my Variables are
iG , k : integer
aarVal : array[1..53] of integer ;
while Not Eof(File) do
Begin
if aarVal[k] > iG then
iG := aarVal[k]
End ;

#

it constantly gives 0

twilit marten
#

while I do not know Pascal/Delhi, it looks like you are iterating something in a file, but in that loop you look in the aarVal array ... also, k is never updated, so it remains 0

mellow venture
#

ok

twilit marten
#

since k = 0 all the time, you are looking at the first element of aarVal ... and since I do not really know how the "while Not Eof(file) do" works, I'm not sure if it loops at all

mellow venture
#

should i change it to a for loop

#

for k = 1 to 53 do

#

instead of if

#

while not Eof(File) do
begin
Readln(File,aarVal) ;

#

for k = 1 to 53 do
begin
then the If ?

twilit marten
#

I'm not sure I understand the wanted output, if you want the max value out of an collection of values, you could iterate that array, but it seems you are trying to get these values out of a file, but never reference to it besides the while loop

#
// this is pseudo code as I do not know delphi
file = open_file("data.txt")
max = 0
while not eof(file) do
begin
  value_from_file = read_line(file)
  if(value_from_file > max)
    max = value_from file
end
#

maybe you can do something like that, note the line under "begin" that actually gets a line from the file

mellow venture
#

ok

mellow venture
twilit marten
#

yes, I guess Readln returns a string or something ? in that case, you need to convert whatever was read to an integer

mellow venture
#

i have set it to read it as an integer

twilit marten
#

should work then

mellow venture
#

ok ill look monday cause not a my computer with delphi but tx for the help

twilit marten
#

but remember, you have to assign whatever readln() returns to a variable, which you then compare to "max"

#

np

pine summit
#

You can just k++ in while loop or do while k < array.size - 1