Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2004
Posts: 2
Reputation: podrock is an unknown quantity at this point 
Solved Threads: 0
podrock podrock is offline Offline
Newbie Poster

Pyramid Issue

 
0
  #1
Nov 3rd, 2004
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??
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 445
Reputation: 1o0oBhP is an unknown quantity at this point 
Solved Threads: 6
1o0oBhP's Avatar
1o0oBhP 1o0oBhP is offline Offline
Posting Pro in Training

Re: Pyramid Issue

 
0
  #2
Dec 18th, 2004
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
http://sales.carina-e.com

no www
no nonsense

coming soon to a pc near you! :cool:
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 207
Reputation: Real-tiner is an unknown quantity at this point 
Solved Threads: 7
Real-tiner Real-tiner is offline Offline
Posting Whiz in Training

Re: Pyramid Issue

 
0
  #3
Jan 6th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 1
Reputation: arunpedha is an unknown quantity at this point 
Solved Threads: 0
arunpedha arunpedha is offline Offline
Newbie Poster

Re: Pyramid Issue

 
0
  #4
Sep 7th, 2009
Originally Posted by 1o0oBhP View Post
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 57
Reputation: omoridi is an unknown quantity at this point 
Solved Threads: 8
omoridi omoridi is offline Offline
Junior Poster in Training

Re: Pyramid Issue

 
0
  #5
Sep 17th, 2009
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
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC