Trouble printing an arrow
Feb 28, 2014 at 11:44pm UTC  
Here I've tried to separate the arrow by pritning the top part then the longest and last the opposite of the top piece. I worked my way form the inside out with the for loops but they don't seem to be coordinating correctly. Any hints so that this is printed?
1What I want to print:
      *
      ***
***********
      ***
      *
  void  printArrow(int  n)
{
    for (int  i = 0; i < n + 1; i++)
    {
        for (int  j = 1; j < n; j += 2)
        {
            for (int  k = 0;k < ((4*n+3)/2); k++)
            {
                cout << ' ' ;                  //sets the spaces 
            }
            if (j == 1)
                cout << '*' ;            //prints the first start alone 
            else 
            {
                for (int  h = 0; h <= j; h++)     //prints the rest 
                    cout << '*' ;
            }
            
            cout << endl;
        }
    }
    for (int  k = n + 1; k < (4 * n + 3);k++)   //middle/longest line in arrow 
    {
        if (k == (4 * n + 3) - 1)                //prints the last star 
            cout << '*' ;
        else                                 //prints the rest 
            cout << '*' ;
    }
    for (int  x = n + 1; x == 0; x--)
    {
        for (int  j = 0; j < n; j -= 2)
        {
            if (j == 0)
                cout << '*' ;            //prints the last start alone 
            else 
            {
                for (int  h = 0; h <= j; h++)     //prints the rest 
                    cout << '*' ;
            }
            cout << setw((n+1)*2) << endl;      //sets the spaces 
            
            cout << endl;
        }
    }
    
    
Last edited on Feb 28, 2014 at 11:45pm UTC  
 
Mar 1, 2014 at 3:03am UTC  
Why don't you explain what you want the arrow to look like for 2 or 3 different given inputs?
 
Mar 1, 2014 at 3:06am UTC  
oh lord, ill never understand the silly exercises they make you do to teach you loops.
 
Topic archived. No new replies allowed.