Loading ...
Sorry, an error occurred while loading the content.

How can introduce two lines of************* to separate two differents answer.

Expand Messages
  • dbermud_e_z
    Hello: I have introduced this to my program in order to separate two answer, with two lines ******* but it is not working. How can I accomplish this? Is there
    Message 1 of 2 , Nov 28, 2005
    • 0 Attachment
      Hello:
      I have introduced this to my program in order to separate two answer,
      with two lines ******* but it is not working.
      How can I accomplish this?
      Is there another way to do this?

      Thank you for you for any inside on this.


      for i=40 to 40
      call prettyprint "*", i
      next i
      for i=40 to 40
      call prettyprint "*",i
      next i
      end

      sub subprogram prettyprint
      sub prettyprint thechar$, n
      for i=1 to 40
      print thechar$;
      next i
      print
      end sub

      'This the program

      dim numb(999)
      print "Enter the higest value to be stored in numb (less than 1000) "
      'I used 593
      input answer
      answer = answer - 1
      for i = 0 to answer
      numb(i) = i
      next i

      print "enter a number to search for: "
      input z ' I used 287
      call sequentialsearch 999,z,x,y
      'Print z; "Number of times table was examined using binary search: ";y
      IF x=1 THEN
      PRINT z;" was find by using sequential search. ";y;" accesses were
      required"

      ELSE

      PRINT z; " NOT IN TABLE"
      END IF


      call sortnumb 999
      call binarysearch 999,z,x,y
      IF x=1 THEN
      PRINT z;" was find by using binary search. ";y;" acces were required"

      ELSE
      PRINT z; " NOT IN TABLE!"
      END IF

      END

      SUB sequentialsearch size,item, BYREF foundit,BYREF hits

      hits=0 'initialize hits
      foundit =0 'initialize foundit
      J=1 'initialize J
      WHILE foundit=0 AND J <= size
      'While loop is executed as long as entry isn't found
      hits=hits+1 'increment count
      IF numb(J) = item THEN
      foundit=1 'we got it
      END IF
      J=J+1
      WEND
      END SUB

      SUB binarysearch size,item, BYREF foundit,BYREF hits
      ' Performs a binary search of size entries in array numb (a global array)
      ' Input variable size indicates how many entries to search
      ' Input variable item contains the number to be found in array numb
      ' variable foundit, returned by reference, is set to 0 if item is not
      found, 1 if it is found
      ' variable hits contains the number of times an entry in numb was searched
      ' The logic is the same as in sample program on page 288 of your book
      hits=0 'initialize hits
      left=1
      foundit=0
      right=size
      time2stop=0
      WHILE time2stop=0
      hits=hits + 1 'increment count
      half=INT( (left+right)/2 ) ' calculate index of halfway point
      IF item < numb(half) THEN
      right=half -1 ' throw away the upper half of the table
      ELSE
      left=half + 1 'throw away the lower half of the table
      END IF
      IF item=numb(half) OR left > right THEN 'we got a hit, or its not
      there
      time2stop=1
      END IF
      WEND
      ' fall through wend when we either have a hit, or we've searched the table
      IF item=numb(half) THEN 'true if we have a hit
      foundit=1
      END IF
      END SUB
      SUB sortnumb size
      'sortnumb subroutine sorts in ascending order the size entries in
      array numb
      FOR i = 1 to size-1
      FOR j=i + 1 to size
      IF numb(i) > numb(j) THEN 'if out of order switch them
      temp=numb(i)
      numb(i)=numb(j)
      numb(j)=temp
      END IF
      NEXT j
      NEXT i
      END SUB
    • pendl2megabit
      Message 2 of 2 , Nov 30, 2005
      • 0 Attachment
        > -----Urspr√ľngliche Nachricht-----
        > Von: libertybasic@yahoogroups.com
        >
        >
        ---snip
        >
        >
        > for i=40 to 40
        > call prettyprint "*",i
        > next i
        > end
        >

        There is no need to use a FOR..NEXT loop, where the starting value is the
        same as the ending value.

        > sub subprogram prettyprint
        > sub prettyprint thechar$, n

        The incomplete first SUB deffinition should raise an error.

        > for i=1 to 40
        > print thechar$;
        > next i
        > print
        > end sub
        >
        ---snip
        >
        >
        > SUB sortnumb size
        > 'sortnumb subroutine sorts in ascending order the size entries in
        > array numb
        > FOR i = 1 to size-1
        > FOR j=i + 1 to size
        > IF numb(i) > numb(j) THEN 'if out of order switch them
        > temp=numb(i)
        > numb(i)=numb(j)
        > numb(j)=temp
        > END IF
        > NEXT j
        > NEXT i
        > END SUB

        You can use LBs SORT command to sort arrays:
        SORT numb(), 1, size
        or
        SORT numb(), size, 1 '(to reverse the order)

        Here is a little function to create a string of one character of a given
        length:

        '---code start
        print string$("*", 40)
        end

        function string$(character$, number)
        for count = 1 to number
        string$ = string$ + character$
        next
        end function
        '---code end

        ---
        Stefan Pendl






        ___________________________________________________________
        Gesendet von Yahoo! Mail - Jetzt mit 1GB Speicher kostenlos - Hier anmelden: http://mail.yahoo.de
      Your message has been successfully submitted and would be delivered to recipients shortly.