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

C++ - Diamond Design

P: 3
Hi, everyone. I was hoping if anyone could help me with writing a general C++ program to receive one word and output to a text file such that the letters of the word are arranged to form a diamond shape. A sample ouput when someone types in a word "DOGGY" in the program will be like this:
Expand|Select|Wrap|Line Numbers
  1.     Y
  2.    YGY
  3.   Y G Y 
  4.  Y  O  Y
  5. YGGODOGGY
  6.  Y  O  Y
  7.   Y G Y
  8.    YGY
  9.     Y
Thank you in advance!
Mar 12 '07 #1
Share this Question
Share on Google+
3 Replies


DeMan
100+
P: 1,806
Naturally, (having read teh Posting Guidelines), you would realise tyhat you will not recieve a solution, merely help along teh way, so I will assume you wanmt to know the method to do this.....
The following will get you the lines, I leave it to you to see if you can add the alignment......(hint: the easiest place to put it would be between the loop statements)

Expand|Select|Wrap|Line Numbers
  1. loop currentletter from 1 to number of letters
  2. loop printletter from one to current letter
  3. print printletter
  4. endloop
  5. print newline
  6. endloop
  7.  
Mar 12 '07 #2

P: 3
TWX
Naturally, (having read teh Posting Guidelines), you would realise tyhat you will not recieve a solution, merely help along teh way, so I will assume you wanmt to know the method to do this.....
The following will get you the lines, I leave it to you to see if you can add the alignment......(hint: the easiest place to put it would be between the loop statements)

Expand|Select|Wrap|Line Numbers
  1. loop currentletter from 1 to number of letters
  2. loop printletter from one to current letter
  3. print printletter
  4. endloop
  5. print newline
  6. endloop
  7.  
Um, sorry, but I still don't quite understand. Can anyone make it clearer? Oh, anyway, sorry that the example output doesn't look like a diamond. For those who are confused and want to see the actual diamond output, please click reply and you will see it in my post. Sincerely sorry for the trouble!
Mar 12 '07 #3

Ganon11
Expert 2.5K+
P: 3,652
You will have to come up with some sort of algorithm to follow when deciding to print what character where. Try tackling this problem step by step. First, you'll need to get the user input into a string. Then, you need to know how many spaces to print before printing the last character, how many lines you need to print, etc.

Take a look at your DOGGY example, and start writing down some numbers: How many lines? How many spaces before the characters in the line? How many spaces between the first Y and the middle letter? Answer these and start looking for a pattern you can utilize.
Mar 12 '07 #4

Post your reply

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