Jump to content

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

Please help!

Thank you!

Link to comment
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
Link to comment
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
Link to comment
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.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
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?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
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
Link to comment
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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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

Please help!

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)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...