Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pyramid Issue
#1
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??
img]http://www.geocities.com/cloud_tifa_zidane/siggy.jpg[/img]
Reply
#2
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~
Reply
#3
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
img]http://www.geocities.com/cloud_tifa_zidane/siggy.jpg[/img]
Reply
#4
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 Big Grin
Reply
#5
Z!re, your too late....he added me to his MSN, and we fixed the problem already

lol

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

Oz~
Reply
#6
DAMIT!, I demand you give me my 30s back!


Or make me some nice sprites for MOo, whatever suits you best =)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)