1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: QBasic problem , simple output program

  1. Dec 7, 2009 #1
    Does anyone know QBasic here? (cuz it is very uncommon)
    Here I have got simple output problem using loop.
    How do I accept a word(any) and print it like this(attached)

    We can use Nested loop,Left$ ,Right$ MID$,and blanks( please don't go into more complex functions cuz I haven't learn't it yet)
    I one the first part all well till" L" but it becomes messy after this!
    PLz help!

    Attached Files:

  2. jcsd
  3. Dec 7, 2009 #2


    Staff: Mentor

    Show us your code. There are probably quite a few of us here with experience in QBasic.
  4. Dec 7, 2009 #3
    You can use the "locate" function.
  5. Dec 7, 2009 #4


    User Avatar
    Science Advisor

    You might like to try something like this:

    INPUT a$
    L = LEN(a$)
    FOR I = 1 TO L
    PRINT LEFT$(a$, I)

    This produces an increasing number of characters of whatever you feed in as the input.

    Since this is in the homework section, you can easily work out from there how to put it in the form you asked for.
  6. Dec 8, 2009 #5
    What about the blanks in front?
  7. Dec 8, 2009 #6


    User Avatar
    Science Advisor

    This is the homework section, so you need to show some work yourself.

    You would put spaces at the beginning of the line so that the total number of characters was equal to the length of the input line. Then you have progressively more spaces and less characters.
    Then do the reverse to get the "V" shape.

    To print a space, you print " ";
    Note the semicolon to avoid starting a new line.

    A better way would be to set up a string like this:
    space$ = "___________________ " (ignore the underlining)
    and take spaces from it with the left$ command.
    Then print these before the left$ part of the input string.
    Last edited: Dec 8, 2009
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook