By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,988 Members | 1,367 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,988 IT Pros & Developers. It's quick & easy.

How to make a diamond shaped asterisk

P: 1
Someone help me how can i display a diamond shaped asterisk correctly pls. correct my program

this is my code:
Expand|Select|Wrap|Line Numbers
  1. Dim ctr, space, asterisk As Integer
  2.  
  3. For ctr = 1 To 9 Step 2
  4.     For space = (9 - 2) / 2 To 0
  5.         LstDisplay.AddItem (" ")
  6.     Next
  7.     For asterisk = 1 To ctr
  8.         LstDisplay.AddItem ("*")
  9.     Next
  10.     LstDisplay.AddItem (" ")
  11. Next
  12.  
  13. For ctr = 7 To 0 Step -2
  14.     For space = (9 - 2) / 2 To 0
  15.         LstDisplay.AddItem (" ")
  16.     Next
  17.  
  18.     For asterisk = 1 To ctr
  19.         LstDisplay.AddItem ("*")
  20.     Next
  21.     LstDisplay.AddItem (" ")
  22. Next
the correct output
Expand|Select|Wrap|Line Numbers
  1. .       *
  2.       * * *
  3.     * * * * * 
  4.   * * * * * * *
  5.  * * * * * * * *
  6.   * * * * * * *
  7.     * * * * * 
  8.       * * *
  9.         *
  10.  
*the correct shape must be diamond not like that*

my output is like this

*

*
*
*

*
*
*
*
*

*
*
*
*
*
*
*

*
*
*
*
*
*
*
*
*

*
*
*
*
*
*
*


*
*
*
*
*

*
*
*

*


pls help me asap i need this on feb 8,08
Feb 4 '08 #1
Share this Question
Share on Google+
1 Reply


P: 58
This seems like homework, so I'm only going to give you tips, not code. One thing to note is that the number of stars, and number of characters, per line should be an odd number, otherwise, the ascii text wouldn't end up looking like a diamond. Decide the maximum number of characters per line. In the example below, the maximum number of characters per line is five. The dashes represent spaces. Now, create a variable called star_line that will hold the spaces and stars. To determine the number of spaces that should be prepended to each star line, use this formula:

number_of_spaces_before_star = ( max_number_characters_per_line - number_of_stars ) / 2

star_line = number_of_spaces_before_star & "*"

print star_line

Expand|Select|Wrap|Line Numbers
  1. --*--
  2. -***-
  3. *****
Feb 4 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.