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?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
What 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?
For instance 6 and 13? What should the arrow look like for those two numbers?
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.