Qbasicnews.com
April 03, 2020, 08:22:06 AM
 Pages: [1]
 Author Topic: Pyramid Issue  (Read 5138 times)
podrock
New Member

Posts: 2

 « on: November 03, 2004, 09:28:27 PM »

Hey I was having a major problem in creating a complex number pyramid. The user inputs a number of rows, but if it exceeds 20 it would go off page, so 1-20. I have a nested For loop (using QBasic) that looks something like this

for x = 1 to rows
for y = 1 to x
(CODE)
next y
(CODE)
next x

IT would be simple ... but the pyramid must look something like this

__________________0
_________________101
________________21012
_______________3210123

That would be for 4 rows, and it continues on in that pattern, with the last number increasing 1 per row....what ive come up with is creating a addition type formula, but i keep gettin the wrong solution and ive changed it about a million different ways so i scratched it all together.....  lol, anyone have an idea on the coding ill need to create the 21012 type pattern in the second For loop....or am i setting it up completly wrong and need a new method of doing this??
 Logged

img]http://www.geocities.com/cloud_tifa_zidane/siggy.jpg[/img]
Oz
I hold this place together

Posts: 923

 « Reply #1 on: November 03, 2004, 09:37:17 PM »

Code:
DIM init AS INTEGER

init = 5

FOR y = 1 to 4
FOR x = 1 to (init - 5) + 1

PRINT SPACE\$(init) + STR\$(x)

NEXT

init = init - 1

next

i think that should work, but i didn't try it

Oz~
 Logged
podrock
New Member

Posts: 2

 « Reply #2 on: November 03, 2004, 09:58:29 PM »

hmm thats creative but for some reason it only returns a row of 1s because the value of X isn't set next to itself horizontal...the object is to get like    3210123   for row 4, then go to the next row
 Logged

img]http://www.geocities.com/cloud_tifa_zidane/siggy.jpg[/img]
Z!re
*/-\*

Posts: 4599

 « Reply #3 on: November 04, 2004, 09:23:17 AM »

Pay attention in class!

Hope you have a test and fail misserably, IF this is homework that is. Which it sure sound like being.

Code:
DEFINT A-Z
CLS

pyrSize = 9

pyr\$ = STRING\$(19, 32)

FOR y = 0 TO pyrSize
ystr\$ = LTRIM\$(RTRIM\$(STR\$(y)))
MID\$(pyr\$, 1 + pyrSize - y) = ystr\$
MID\$(pyr\$, 1 + pyrSize + y) = ystr\$
PRINT pyr\$
NEXT

Happy, you made me waste 30s of my life
 Logged
Oz
I hold this place together

Posts: 923

 « Reply #4 on: November 04, 2004, 10:49:39 AM »

lol

oh well......we probably should have said something in the post

Oz~
 Logged
Z!re
*/-\*

Posts: 4599

 « Reply #5 on: November 04, 2004, 01:57:48 PM »

DAMIT!, I demand you give me my 30s back!

Or make me some nice sprites for MOo, whatever suits you best =)
 Logged
 Pages: [1]