Qbasic-Array - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Qbasic-Array

Hugo2k99Hugo2k99 Posts: 2Member
I need the user to enter a phrase, every letter of the phrase is to go into an array, which I would then display. The problem is that phrase would include commas and points, but when I type a comma, I get a "redo from start". How can I allow the user to enter commas into the phrase.

This is what I have:

INPUT "Enter a phrase: ", Phrase$
PRINT
Length = LEN(Phrase$)
PRINT Length
DIM Word$(1 TO Length)
FOR Count = 1 TO Length
Letter$ = MID$(Phrase$, Count, 1)
Word$(Count) = Letter$
PRINT Word$(Count);
NEXT Count




Comments

  • Dr. COM WIZDr. COM WIZ Posts: 74Member
    : I need the user to enter a phrase, every letter of the phrase is to go into an array, which I would then display. The problem is that phrase would include commas and points, but when I type a comma, I get a "redo from start". How can I allow the user to enter commas into the phrase.
    :
    : This is what I have:
    :
    : INPUT "Enter a phrase: ", Phrase$
    : PRINT
    : Length = LEN(Phrase$)
    : PRINT Length
    : DIM Word$(1 TO Length)
    : FOR Count = 1 TO Length
    : Letter$ = MID$(Phrase$, Count, 1)
    : Word$(Count) = Letter$
    : PRINT Word$(Count);
    : NEXT Count
    :
    : The answer to your question is very simple. I, too had this problem once before when I was 12. Just do this:

    [code]
    LINE INPUT "Enter a phrase: ";Phrase$
    [/code]

    LINE INPUT will allow the user to enter any punctuation or symbols. However, LINE INPUT will never prompt the user with a question mark as does INPUT. So, if you're asking the user a question, you must insert the question mark.
    :
    :


  • Dr. COM WIZDr. COM WIZ Posts: 74Member
    : : I need the user to enter a phrase, every letter of the phrase is to go into an array, which I would then display. The problem is that phrase would include commas and points, but when I type a comma, I get a "redo from start". How can I allow the user to enter commas into the phrase.
    : :
    : : This is what I have:
    : :
    : : INPUT "Enter a phrase: ", Phrase$
    : : PRINT
    : : Length = LEN(Phrase$)
    : : PRINT Length
    : : DIM Word$(1 TO Length)
    : : FOR Count = 1 TO Length
    : : Letter$ = MID$(Phrase$, Count, 1)
    : : Word$(Count) = Letter$
    : : PRINT Word$(Count);
    : : NEXT Count
    : :
    : : The answer to your question is very simple. I, too had this problem once before when I was 12. Just do this:
    :
    : [code]
    : LINE INPUT "Enter a phrase: ";Phrase$
    : [/code]
    :
    : LINE INPUT will allow the user to enter any punctuation or symbols. However, LINE INPUT will never prompt the user with a question mark as does INPUT. So, if you're asking the user a question, you must insert the question mark.
    --Dr. COM WIZ
    : :
    : :
    :
    :

    This has been,
    Dr. COM WIZ
    PS Thank you and goodnight!


  • BASIC FriendBASIC Friend Posts: 354Member
    : I need the user to enter a phrase, every letter of the phrase is to go into an array, which I would then display. The problem is that phrase would include commas and points, but when I type a comma, I get a "redo from start". How can I allow the user to enter commas into the phrase.
    :
    : This is what I have:
    :
    : INPUT "Enter a phrase: ", Phrase$
    : PRINT
    : Length = LEN(Phrase$)
    : PRINT Length
    : DIM Word$(1 TO Length)
    : FOR Count = 1 TO Length
    : Letter$ = MID$(Phrase$, Count, 1)
    : Word$(Count) = Letter$
    : PRINT Word$(Count);
    : NEXT Count
    :
    :
    :
    :

    What comwiz said. But, I was looking at your code and I realized that you could use a function to simulate an array of characters.(strings are arrays of characters anyways).

    I'm writing this on the fly, so there might be a bug or two in it.

    [code]
    FUNCTION CharArray$(a$,n%)
    l% = LEN(a$)
    r$ = ""
    IF NOT n% > l% THEN
    r$ = MID$(a$, n%, 1)
    END IF
    CharArray$ = r$
    END FUNCTION

    INPUT "Enter a phrase: ", Phrase$
    PRINT
    Length% = LEN(Phrase$)
    PRINT Length%
    FOR Count% = 1 TO Length%
    PRINT CharArray$(Phrase$, count%)
    NEXT Count%
    [/code]
    This only works for getting the element from the string.


  • Hugo2k99Hugo2k99 Posts: 2Member
    Thanks for the help.

Sign In or Register to comment.