max
and min
the best? Would you code work in all cases? Was your code 'robust?'
min
initially to 100
, but suppose your data file contained a bunch of numbers that were all only in the 1000s? Your code would say 100 was in the minimum, but 100 isn't even in the data file!
max
to 0
, but your data file contained all negative numbers?
min
and max
to some number that is actually in your data file. How will you do this?
min
or max
equal to the first number in your data file? It may or may not end up being the eventual minimum or maximum value, but at least it's in the data file, as a reference for starting out the comparisions.
h = file_open("sample.dat")
if h == -1 then
print("ERROR! The file cannot be used.")
else
min = ??
while not file_eof(h) do
num = file_read_number(h)
if num < min then
min = num
end
end
print("Minimum=",min)
end
min = ??
line? Think: not a number like before, but the first number in your data file.