944,128 Members | Top Members by Rank

Ad:
Nov 3rd, 2004
0

Pyramid Issue

Expand Post »
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..... :mad: 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??
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
podrock is offline Offline
2 posts
since Nov 2004
Dec 18th, 2004
0

Re: Pyramid Issue

Just a thought:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2. CLS
  3. row = 0
  4. For y = 0 to 19 ' 20 rows
  5. For x = 0 to row
  6. print "x" ' i cant remember the code for adjacent text
  7. Next
  8. print " " 'new line
  9. row = row + 1 ' increment row
  10. Next

this should give you

0
01
012
0123
...

and im sure you can go back over the loop and draw the other side
Reputation Points: 16
Solved Threads: 6
Posting Pro in Training
1o0oBhP is offline Offline
445 posts
since Dec 2004
Jan 6th, 2005
0

Re: Pyramid Issue

First of all, you need a nonkerning font....

Second, I would use the concatenating + in an assignment statement to give you what you need, such as:

nu$ = STR$(i)
hol$ = nu$ + lis$ + nu$
lis$ = hol$

This adds the new number to both ends of the string lis$.

Now all you have to do is figure out how to use STRING$ to make a line of dashes, one dash shorter than the previous time.
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
Real-tiner is offline Offline
207 posts
since Dec 2004
Sep 7th, 2009
0

Re: Pyramid Issue

Click to Expand / Collapse  Quote originally posted by 1o0oBhP ...
Just a thought:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2. CLS
  3. row = 0
  4. For y = 0 to 19 ' 20 rows
  5. For x = 0 to row
  6. print "x" ' i cant remember the code for adjacent text
  7. Next
  8. print " " 'new line
  9. row = row + 1 ' increment row
  10. Next

this should give you

0
01
012
0123
...

and im sure you can go back over the loop and draw the other side

To achieve the single line printing, please refer the below code. Hope this helps.....

Dim res As String
res = ""
row = 0
For y = 1 To 6 ' 20 rows
For x = 1 To row
res = res & "x"
Next
Print res
res = ""
row = row + 1 ' increment row
Next


Output will be as follows
x
xx
xxx
xxxx
xxxxx
Reputation Points: 10
Solved Threads: 0
Newbie Poster
arunpedha is offline Offline
1 posts
since Sep 2009
Sep 17th, 2009
0

Re: Pyramid Issue

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim x As Long
  2. Dim y As Long
  3. Dim S As String
  4. For y = 0 To 20
  5. S = ""
  6. For x = -y To y
  7. S = S & Abs(x)
  8. Next
  9. Print Space(100 - Len(S)) & S
  10. Next
Reputation Points: 10
Solved Threads: 10
Junior Poster in Training
omoridi is offline Offline
72 posts
since Sep 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: VB6 age calculator
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Do until loop





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC