1 Replies - 2713 Views - Last Post: 19 January 2011 - 08:03 PM Rate Topic: -----

#1 JulianJP118  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 24-March 10

Star/Diamond

Posted 19 January 2011 - 05:48 PM

Hi! I'm trying to make a diamond, starting with the simple form of a triangle. This is what I have so far:

but something is messed up with my fill loop, the stars are printing backwards. Any ideas would be greatly appreciated (:
int size = 7; 
char border = '^'; 
char fill = '*'; 
char space = ' '; 
int counter; 
int row; 

for (int col = 0; col <= size; col++)
{
	for (row = 0; row <= size; row++)
	{
		for (counter = 0; counter < size; counter++)
			cout << counter; 
		{
			if (counter == size)
			{
				cout << border;  
				cout << " "; 
			}
				for (counter = 0; counter < size; counter++)
				cout << fill; 

			cout << '\n'; 
			size--; 
		}
		}
}


This post has been edited by macosxnerd101: 19 January 2011 - 06:28 PM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Star/Diamond

#2 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1368
  • View blog
  • Posts: 4,737
  • Joined: 19-February 09

Re: Star/Diamond

Posted 19 January 2011 - 08:03 PM

You don't need this column for loop, because the loops using counter, print each column on the row, and so have the same effect.
for (int col = 0; col <= size; col++)



The triangle prints from wide to small because you start off with size being large then decrementing it.

If you start with size being small and incrementing it, I think you will manage to print the triangle the other way up.

One problem, you will encounter, is that you are using size in the row for loop, for a different reason, so I would think about using another variable there.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1