[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

C++ Program to make a bow tie

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 4
Thread images: 2

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
}
>>
File: file.png (66KB, 900x980px) Image search: [Google]
file.png
66KB, 900x980px
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
Thread posts: 4
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

If you need a post removed click on it's [Report] button and follow the instruction.
If you like this website please support us by donating with Bitcoin at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties. Posts and uploaded images are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that website. If you need information about a Poster - contact 4chan. This project is not affiliated in any way with 4chan.