Hi steiny.
Welcome to the forum! Just to get it right. You want to enter 10 numbers, store them in an array. Then sort them descending? Adn then print them in the console window?
Best wishes
Michael
I am having trouble with array's and learning the tbasic language so my question is this. Using the console module, what would be the correct way to write an application that allows you to enter 10 numbers and display them in descending order?
Hi steiny.
Welcome to the forum! Just to get it right. You want to enter 10 numbers, store them in an array. Then sort them descending? Adn then print them in the console window?
Best wishes
Michael
That is correct.
Ciao steney and welcome to thinBasic community forum.
I just write down a little example that can give you a start.
[code=thinbasic]
Uses "Console"
Dim HowManyNumbers As Integer
Dim MyNumber As Number
Dim MyArray() As Number
Dim Counter As Long
Do
Print "How many numbers (1 to 10): "
HowManyNumbers = Console_ReadLine
Loop While Outside(HowManyNumbers, 0, 10)
If HowManyNumbers > 0 Then
ReDim MyArray(HowManyNumbers)
For Counter = 1 To HowManyNumbers
Print "Enter number " & Counter & ": "
MyArray(Counter) = Console_ReadLine
Next
PrintL "---Printing out sorted ---"
Array Sort MyArray
For Counter = 1 To HowManyNumbers
PrintL Format$(Counter, "00") & ": ", MyArray(Counter)
Next
PrintL "--------------------------"
PrintL "<Press a key to finish>"
Console_WaitKey
Else
PrintL "---Ok, no numbers---------"
PrintL "<Press a key to finish>"
Console_WaitKey
End If
[/code]
Ciao
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Thanks for the help Eros.
Hi Steiny,
Also (from helpfile) to sort an array in descending order:
ARRAY SORT ArrayVariable([StartIndex]) [FOR nElements] [,{ASCEND | DESCEND}]
catventure.
http://tab.thinbasic.com - Home Of The ThinBasic Adventure Builder Project. (Interactive Fiction/Text Adventure Maker)
oops, sorry I forgot about descending order.
Just change one line in script from
[code=thinbasic]Array Sort MyArray[/code]
to
[code=thinbasic]Array Sort MyArray, DESCEND[/code]
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
...may be this help too.
I have tried this very short way, but with no descend way, I have never tried it before
[code=thinbasic]' Empty GUI script created on 11-05-2009 20:47:57 by (ThinAIR)
uses "console"
dim n as long
DIM arrays( 20 ) AS INTEGER
arrays(1) = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
ARRAY SORT arrays(20) FOR 1, descend
' -- Print line of array items joined by space
PRINTL JOIN$( Arrays, " " )
WAITKEY[/code]
welcome steiny and have fun with thinbasic
bye, frank
you can't always get what you want, but if you try sometimes you might find, you get what you need
Bookmarks