Teen Programmers Unite  
 

 

Return to forum top

rhombus program

Posted by jackal [send private reply] at October 18, 2001, 05:23:36 PM

hey everyone i really need help with this following program, my team member and i have been trying to figure this out for weeks..please help!(started the program by creating a set of nested loops but still couldnt figure out)

*a program that print the square full of specific numbers s.t. all numbers along the main diagonals are skipped and replaced by stars. output like this:

user promt:
What is the length of the diagonal (odd number)?
9

*
3 * 3
5 5 * 5 5
* * * * * * *
5 5 * 5 5
3 * 3
*




Posted by Psion [send private reply] at October 18, 2001, 05:30:47 PM

You definitely have not explained the problem to us yet. Also note that our policy here is not to just do your homework for you. However, with more info, maybe we can guide you in the right direction.

Posted by jackal [send private reply] at October 18, 2001, 05:37:44 PM

i totally understand the policy and apoligize if i'd gave the wrong impression..we're just trying to figure out the formula or structure to create this rhombus figure(this is my first time in c++)..the only thing we got started on is a nested loops..

*
3 * 3
5 5 * 5 5
* * * * * * *
5 5 * 5 5
3 * 3
*


Posted by jackal [send private reply] at October 18, 2001, 05:40:00 PM

*
3 * 3
5 5 * 5 5
* * * * * * *
5 5 * 5 5
3 * 3
*


Posted by Psion [send private reply] at October 18, 2001, 05:52:05 PM

Obviously if you just want that figure, you can print it exactly. What I don't see is how the input leads to a specific figure. Explain it to me like you'd explain it to a dumb computer, because that's what you'll have to do in the end. :-)

Posted by jackal [send private reply] at October 18, 2001, 06:06:29 PM

The object is not printing properly on the page. It is supposed to be a diamond shape with all the main diagonals are skipped and replaced by stars.

Such as:

If a user inputs a (length of diagonal) 5.

It would display the center as ***** (5 stars) then either working upwards or downwards it would minus two from the original number and output the remainder with number * number (according to how many is left)

In thise case the next line would be 3 * 3 (either going up or down on the diamond) and the final line just being a *.

If this diamond was created all the center pieces would be stars and the rest would be replaced by numbers...have I throughly confused the dumb computer? ;)

*
3*3
*****
3*3
*



Posted by jackal [send private reply] at October 18, 2001, 06:06:57 PM

View the source of the document to see what it should look like :)

Posted by grandsnafu [send private reply] at October 18, 2001, 08:25:36 PM

is it just the formatting that's off? if it is, pad the output of each line by doing some fancy math with the diagonal length.
better yet, how much of the program is working?

Posted by Psion [send private reply] at October 19, 2001, 02:20:29 PM

And how do you know which spots are 3's and which are 5's?

Posted by taubz [send private reply] at October 19, 2001, 02:40:56 PM

Here's what I think you're trying to say.... The user inputs a number, N (assume odd). This is the horizonal width of the "diamond" at the middle. For each line going up, the width of the "line" drawn is two less then the previous line, drawn using the charcter for the number reprenting the width of that line, with the center character replaced with an *. Same for going down. All righty.

Start printing from the top (duh). What do you print for the first line? Just a single asterisk. No matter what N is, it's always just 1 *. But where? Well, it's in line with the center of the diamond. Where is that? If the width of the diamond is N, then the center is at N/2 characters over. So, you have to print N/2-1 spaces, and then an asterisk, and then a new line.

Okay, so now we're on the second line. Let's assume N > 3. The lenght of the first line was 1, so now it's 3 (two more). So, we'll print 3's, with an * in the center. How many 3's will we print? Two - one on the left of the * and one on the right side. So, we have to print one less space than we did last time, then print a 3, then a *, then a 3 again. Newline.

There's a pattern here... finally you get to the N line. Just print N asterisks.

Now do it again in reverse.

Did that make sense?

- taubz

Posted by gian [send private reply] at October 19, 2001, 03:35:17 PM

Makes sense to me....

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.