Program help

ok guys I need some help. I have to write a program for my class and im haveing trouble with it. It has to be written in qbasic. This is the only program I have had trouble with and I would like to know if anyone could help.

The program has to have the user input a number and then the output has to be like this

B = Blank Space

123454321
1234B4321
123BBB321
12BBBBB21
1BBBBBBB1

I know I have to use loops but I have spent hours trying to get this to work and I havent had any luck yet. Can someone please help me??

Comments

  • So far this is what I got.

    cls
    input "enter a number", x
    b=x
    for i = 1 to x
    for a = 1 to b
    locate (i,a)
    print a
    next a
    b=b-1
    next i

    that should produce.

    12345
    1234
    123
    12
    1

    But it doesnt for some reason
  • Ok this is all ive got. I still dont know why it wont work. can anyone help me please?

    cls
    input "enter a number", x
    b=x
    for i = 1 to x
    for a = 1 to b
    locate (i,a)
    print a
    next a
    b=b-1
    next i

    i=x+1
    a=x
    for i=i to 1 step -1
    a=i-1
    for a=a to 1 step -1
    locate (i,a)
    print a
    next a
    next i


  • : ok guys I need some help. I have to write a program for my class and im haveing trouble with it. It has to be written in qbasic. This is the only program I have had trouble with and I would like to know if anyone could help.
    ::
    :: The program has to have the user input a number and then the output has to be like this
    ::
    :: B = Blank Space
    ::
    :: 123454321
    :: 1234B4321
    :: 123BBB321
    :: 12BBBBB21
    :: 1BBBBBBB1
    ::
    :: I know I have to use loops but I have spent hours trying to get this to work and I havent had any luck yet. Can someone please help me??
    ::
    : Ok this is all ive got. I still dont know why it wont work. can anyone help me please?
    :
    : cls
    : input "enter a number", x
    : b=x
    : for i = 1 to x
    : for a = 1 to b
    : locate (i,a)
    : print a
    : next a
    : b=b-1
    : next i
    :
    : i=x+1
    : a=x
    : for i=i to 1 step -1
    : a=i-1
    : for a=a to 1 step -1
    : locate (i,a)
    : print a
    : next a
    : next i
    :
    1) Loops should be indented so they can be read, you therefore must use code tags on the board so we can read what you are doing.
    2) I assume the number to enter is the number 5 in this example. You need to state that information if it's relevant to the problem.
    3) you don't need any locate statements for this.
    4) to output a value without the return at the end of the line, use a semicolon at the end of the line:
    print a;
    5a) Start with just the very first line "123454321". Write the code using couple loops to output this pattern.
    5b) Next write the code to do the last line "1bbbbbbb1".
    5c) Figure out the similarities in the code for those two lines, and combine them into one piece of code that can output all the lines.
    6) Put all that inside one more loop to process all the lines

    ----------------
    Walt


  • im not sure exactly how your instructor wants your code to work...this seems like a very fake way of doing it, but it does get the right output..if i understand correctly
    [code]
    CLS
    INPUT "Enter a number:", x
    b = x
    FOR i = 1 TO x
    p$ = p$ + RIGHT$(STR$(i), LEN(STR$(i)) - 1)
    NEXT
    FOR i = x - 1 TO 1 STEP -1
    p$ = p$ + RIGHT$(STR$(i), LEN(STR$(i)) - 1)
    NEXT
    PRINT p$
    FOR a = 1 TO x
    p$ = ""
    FOR i = 1 TO b - 1
    p$ = p$ + RIGHT$(STR$(i), LEN(STR$(i)) - 1)
    NEXT
    p$ = p$ + STRING$(x - b, " ") + " "
    PRINT p$;
    p$ = ""
    FOR i = b - 1 TO 1 STEP -1
    p$ = p$ + RIGHT$(STR$(i), LEN(STR$(i)) - 1)
    NEXT
    p$ = STRING$(x - b, " ") + p$
    PRINT p$
    b = b - 1
    NEXT
    [/code]

    there is probably a much better way of doing this..

    and it messes up the output on 2 digit numbers..is it supposed to work on numbers above 9? anyway, i hope this helps

    : ok guys I need some help. I have to write a program for my class and im haveing trouble with it. It has to be written in qbasic. This is the only program I have had trouble with and I would like to know if anyone could help.
    :
    : The program has to have the user input a number and then the output has to be like this
    :
    : B = Blank Space
    :
    : 123454321
    : 1234B4321
    : 123BBB321
    : 12BBBBB21
    : 1BBBBBBB1
    :
    : I know I have to use loops but I have spent hours trying to get this to work and I havent had any luck yet. Can someone please help me??
    :

Sign In or Register to comment.

Howdy, Stranger!

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

Categories