I'm sorta new to c++ and I have to make a program to make a bow tie. It should look like the pic uploaded. I don't know how to start apart from the usual,
int main ()
{
int n;
cout << "Enter n... ";
cin>>n
These are the functions if I should call them that: 2n + 1 height, 2n + 2 width.
2n + 2 - 2i
2*4 + 2 - 2= 8, i= 1
2*4 + 2-2*2= 6, i=2
Does anyone know how to do or start this? Any help appreciated!
>>270886
Start by thinking about the output one line at a time, because that's what your program will be doing.
Each line will have a total of 2n + 2 characters. Since you most likely are going to use a loop for this, the amount of stars and spaces depends on what step you are on the loop. Let's say you are using i as your iterating variable. You would have 2i *s each line and the rest will be the spaces in between. That is just the total amount of characters each line is - the amount of stars each line (2n + 2 - 2i).
Since the spaces are in between the *s, each line can be summed up as: 'i' amount of stars + '2n + 2 - 2i' amount of spaces + 'i' amount of stars.
Here's some shitty pseudo code so you can do the work yourself.
loop (i = 1 to n)
{
print '*'*i + ' '*(2n + 2 - 2i) + '*'*i
}
There are way too many ways to go about it, all of the smart ones make use of a loop.
I'd personally make 4 triangles.
Here's my implementation in python
>>270886
So the star-count on the left goes up to n and then start to decrease again. While printing n-(current count of printed stars spaces). And then does the same thing again in the line but prints the spaces first?
Left half.
n=1
*
n=2
*s
**
*s
n=3
*ss
**s
***
**s
*ss
n=4
*sss
**ss
***s
****
***s
**ss
*sss