# How to find out which is the smallest number?

## Recommended Posts

Hi!

I was wandering how to found out what is the smallest number out of 5

I have already managed to do the same with 2 numbers (

```Local \$a = Random(1, 100)
Local \$b = Random(1, 100)
Local \$c = Random(1, 100)
Local \$d = Random(1, 100)
Local \$e = Random(1, 100)

Local \$f = \$a - \$b

If \$f > 0 Then
MsgBox(0, "The bigger number is", \$a)
EndIf
If \$f < 0 Then
MsgBox(0, "The bigger number is", \$b)

EndIf
If \$f = 0 Then
MsgBox(0, "Szám", "The numbers are equal")
EndIf```

but i cannot do it with 5

Thank you!

##### Share on other sites

make an array out of them.

```local \$minimum,\$index,\$amountofnumbers = 5
local \$array[\$amountofnumbers]

for \$i=1 to \$amountofnumbers
\$array[\$i] = Random(1, 100)
next
\$minimum = \$array[1]
\$index = 1
for \$i=2 to ubound(\$array)-1
if (\$array[\$i] < \$minimum ) Then
\$minimum = \$array[\$i]
\$index = \$i
Endif
next```

Its more like pseudo code, but something like this should work.

Edited by cageman
##### Share on other sites

Sorry im a newbie how can i make an array?

##### Share on other sites

```local \$size = 5
local \$myarray[\$size]

\$myarray[4] = 8```

would make a variable \$myarray, which is an array of size 5). Thus contains 5 values.

You can set one of the values, by selecting \$myarray[4], would select the 4th value.

The zero value in the array is the number of elements \$myarray[0] would thus be equal to 5.

Edited by cageman
##### Share on other sites

Thanks but how can i reach the script to write it out in a MsgBox ?

##### Share on other sites

Or could you just write the whole script in one piece please?

##### Share on other sites

Sorry im a newbie how can i make an array?

Not a valid excuse around here I'm afraid. Why not look in the help file for arrays first as someone providing an example here isn't that much help if you don't understand them.
##### Share on other sites

i have checked it but i do not understand it so sorry :S

##### Share on other sites

Really? It's not something you can grasp in 20 seconds of reading the help file. You have to search the forum, find examples and learn. What about this >> http://www.autoitscript.com/wiki/Arrays did you find this when searching about arrays?

##### Share on other sites

If you put in the effort yourself, once in a while people will throw code at you to help, because they know you attempt on your own.

If not, I guarantee you will not find what you are looking for here.

Making an array is one of the first few things you learn just by reading some basics about autoit.

didn't even open scite and look at the help file..

first item that popped up on google: http://en.wikipedia.org/wiki/AutoIt

Check it out..

Edited by caleb41610
##### Share on other sites

Yes. I am really sorry but as I said I am newbie to programming.

Could you help me nayway?

##### Share on other sites

• Developers

Yes. I am really sorry but as I said I am newbie to programming.

Could you help me nayway?

They have been clear. Next post on this topic without any demonstration of effort will urn you a short posting vacation from these forums. Edited by Jos

Live for the present,
Dream of the future,
Learn from the past.

##### Share on other sites

Okay. I am really sorry.

Thank you all for helping!

##### Share on other sites

Hi!

I was wandering how to found out what is the smallest number out of 5

I have already managed to do the same with 2 numbers (

```Local \$a = Random(1, 100)
Local \$b = Random(1, 100)
Local \$c = Random(1, 100)
Local \$d = Random(1, 100)
Local \$e = Random(1, 100)

Local \$f = \$a - \$b

If \$f > 0 Then
MsgBox(0, "The bigger number is", \$a)
EndIf
If \$f < 0 Then
MsgBox(0, "The bigger number is", \$b)

EndIf
If \$f = 0 Then
MsgBox(0, "Szám", "The numbers are equal")
EndIf```

but i cannot do it with 5

Thank you!

Expanding your example, and not using arrays, there is this example.

```Local \$a = Random(1, 100, 1)
Local \$b = Random(1, 100, 1)
Local \$c = Random(1, 100, 1)
Local \$d = Random(1, 100, 1)
Local \$e = Random(1, 100, 1)

Local \$sText = _
"\$a = " & \$a & @LF & _
"\$b = " & \$b & @LF & _
"\$c = " & \$c & @LF & _
"\$d = " & \$d & @LF & _
"\$e = " & \$e & @LF & "The smallest number is"

If \$a <= \$b And \$a <= \$c And \$a <= \$d And \$a <= \$e Then \$sText &= ", \$a = " & \$a
If \$b <= \$a And \$b <= \$c And \$b <= \$d And \$b <= \$e Then \$sText &= ", \$b = " & \$b
If \$c <= \$a And \$c <= \$b And \$c <= \$d And \$c <= \$e Then \$sText &= ", \$c = " & \$c
If \$d <= \$a And \$d <= \$b And \$d <= \$c And \$d <= \$e Then \$sText &= ", \$d = " & \$d
If \$e <= \$a And \$e <= \$b And \$e <= \$c And \$e <= \$d Then \$sText &= ", \$e = " & \$e

MsgBox(0, "Results", \$sText)```

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...