Thread: Need Help Displaying A Pattern.

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    21

    Need Help Displaying A Pattern.

    Hello, I need help displaying this pattern by using loops and only putting one multiplication sign on in a cout statement.


    * *
    *** *
    ***** *
    ******* *
    ********* *
    -Okay this pattern isn't displaying correctly when I post it. All the stars have to be aligned on the right side.

    This is what I have done so far, but I am having trouble getting the pattern. Thanks in Advance.



    Code:
    #include <iostream>
    
    using namespace std;
    
    int main ()
    {
    	
    	for (int row = 0; row <5; row++)
    	{
    			for (int star = 0; star < 10; star++)
    			{
    					cout<<'*';
    					if(star == 1)
    					break;
    					
    			}
    			cout<<" "<<'*';
    			cout<<endl;
    
    		
    
      
    	}
    
    
    	return 0;
    
    }
    Last edited by slickwilly440; 10-04-2005 at 10:06 PM.

  2. #2
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    Quote Originally Posted by slickwilly440
    Hello, I need help displaying this pattern by using loops and only putting one multiplication sign on in a cout statement.


    * *
    *** *
    ***** *
    ******* *
    ********* *
    -Okay this pattern isn't displaying correctly when I post it. All the stars have to be aligned on the right side.

    This is what I have done so far, but I am having trouble getting the pattern. Thanks in Advance.
    There's a function to make things aligned to the right, I think its a member of std. Search google.com for aligning text to the right and you should find something. The pattern is something you're going to have to figure out yourself through trial and error. Unless a developer here is willing to do it for you .
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > for (int star = 0; star < 10; star++)
    Try for (int star = 0; star < row; star++)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Information Crocodile
    Join Date
    Dec 2004
    Posts
    204
    C way.

    try make
    Code:
    for (int star = 0; star < 10; star++)
    to
    Code:
    for (int star = 10; star > 0 or 1??; star--)
    int row should start with 1 and row < 5 to row <= 5


    print asterisk only if star is less or equals to row, else print space

    Code:
          *
        **
      ***
    ****
    Last edited by loko; 10-05-2005 at 01:28 AM.

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    21
    Thanks Guys, I will try this later when I have time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visitor / Decorator Pattern
    By MarkZWEERS in forum C++ Programming
    Replies: 9
    Last Post: 05-16-2009, 11:53 AM
  2. Hmm.. Ai? Finding the pattern in number squences?
    By Zeusbwr in forum C++ Programming
    Replies: 8
    Last Post: 04-02-2005, 06:13 PM
  3. (pattern *) pat & pattern * pat
    By siubo in forum C Programming
    Replies: 1
    Last Post: 04-08-2003, 10:03 PM
  4. How do I print a pattern flush right?
    By Basia in forum C Programming
    Replies: 5
    Last Post: 06-11-2002, 07:15 AM
  5. text pattern recognition
    By mtsmox in forum C++ Programming
    Replies: 5
    Last Post: 02-27-2002, 08:38 AM