Results 1 to 8 of 8

Thread: newbie question

  1. #1

    newbie question

    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?

  2. #2

    Re: newbie question

    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

  3. #3

    Re: newbie question

    That is correct.

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: newbie question

    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
    Attached Files Attached Files
    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

  5. #5

    Re: newbie question

    Thanks for the help Eros.

  6. #6

    Re: newbie question

    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)

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: newbie question

    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

  8. #8
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    934
    Rep Power
    109

    Re: newbie question

    ...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

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •