QBasic problem , simple output program

In summary, the conversation discusses using QBasic to accept a word and print it in a specific format using nested loops and string manipulation functions. The code provided uses the "locate" function and a loop to print an increasing number of characters from the input word. The conversation also mentions using spaces to create a "V" shape in the output and suggests using a string to make this process easier.
  • #1
1/2"
99
0
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 because I haven't learn't it yet)
I one the first part all well till" L" but it becomes messy after this!
PLz help!
 

Attachments

  • untitled3.bmp
    66.6 KB · Views: 574
Physics news on Phys.org
  • #2
Show us your code. There are probably quite a few of us here with experience in QBasic.
 
  • #3
You can use the "locate" function.
 
  • #4
You might like to try something like this:

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

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.
 
  • #5
What about the blanks in front?
 
  • #6
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:

Related to QBasic problem , simple output program

1. What is QBasic?

QBasic is a programming language developed by Microsoft in the early 1990s. It is a simple, easy-to-learn language that is often used for educational purposes or for creating small, simple programs.

2. How do I write a simple output program in QBasic?

To write a simple output program in QBasic, you will need to use the PRINT statement. This statement allows you to print text or numbers to the screen. For example, you could write "PRINT "Hello world"" to print the phrase "Hello world" to the screen.

3. What is the syntax for the PRINT statement in QBasic?

The syntax for the PRINT statement in QBasic is "PRINT expression". The expression can be any text or number that you want to print to the screen. You can also use multiple PRINT statements in a row to print multiple lines of text.

4. How do I run a QBasic program?

To run a QBasic program, you will need to use the QBasic interpreter, which is a program that reads and executes QBasic code. You can open the QBasic interpreter and then type in your code or open a saved .BAS file. To run the program, press the F5 key on your keyboard.

5. Can I create more complex programs in QBasic?

While QBasic is a simple language, you can create more complex programs by using features such as loops, conditional statements, and user-defined functions. However, if you are looking to create more advanced programs, you may want to consider learning a different programming language.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
18
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
2K
  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
21
Views
3K
Back
Top