Posted 14 September 2012 - 02:06 AM
I'm surprised no one asked this before. How do I compare three values at the same time? In this case, to find the greatest number. Can this be shortened:
I pulled that out of my hat, so there may be errors, but you see what I'm trying to do. That will get ridiculously lengthy very quickly. And I was only trying to compare three numbers! Imagine if I had 20.
I've never been taught any programming language, save for HTML (and I know it doesn't count), so I learned most of what I know here at the forums/wiki. That's why I'm asking what is almost certainly a "noob" question.
–Lettuce
Spoiler
--dummy code
x1 = 1
x2 = 2
x3 = 3
if x1 > x2 then
if x1 > x3 then
print "x1 is greatest."
end
elseif x2 > x1 then
if x2 > x3 then
print "x2 is greatest."
end
end
elseif x1 == x2 or x2 == x3 or x1 == x3 then
print "At least two values are the same.
end
else
print "x3 is greatest."
end
end
I pulled that out of my hat, so there may be errors, but you see what I'm trying to do. That will get ridiculously lengthy very quickly. And I was only trying to compare three numbers! Imagine if I had 20.
I've never been taught any programming language, save for HTML (and I know it doesn't count), so I learned most of what I know here at the forums/wiki. That's why I'm asking what is almost certainly a "noob" question.
–Lettuce