really need help

Hi, I just started c++ this week. I am learning while loops today and I am really stuck on this question and I don't know how to begin it. I'm supposed to use nested while loops to make a bow tie asterisk like this:

*-------------*
***-------***
**********
***------***
*-------------*

the dashes are meant to be spaces.

I need to enter in a height, the bow tie on top would have a height of 5.
I think someone asked the same question as this and it never got replied. I will thank anyone who will help a stupid beginner like me with this question.
Last edited on
ok there you go
open this link and you'll see a step-by-step illustration to make stars formation
http://www.mediafire.com/view/?814ody1ab90iq31
good luck
If you want I can post the solution I did with the nested while loop. It's pretty crude but it does the job. Or I can roughly tell you how I did it and you can work it out.
Is it ok for me to see the code, because I'm not quite sure how to start the code. I just began while loops today
Last edited on
Yea sure here it is.

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
#include<iostream>
using namespace std;

int main()
{
    int x = 0, y = 9;
    int col = 0, row = 0;
    int cnt = 0;

    while (col < 5)
    {
        while (row < 10)
        {
            if (row <= x || row >= y)
            {
                cout << "*";
            }
            else
            {
                cout << " ";
            }

            ++row;

        }

        if (row == 10)
        {
            cout << endl;
            ++cnt;
        }

        if (cnt <= 2)
        {
            x += 2;
            y -= 2;
        }
        else
        {
            x -= 2;
            y += 2;
        }

        row = 0;
        ++col;
    }
    return 0;
}


Edit: Feel free to ask any questions.
Last edited on
I'm supposed to enter in a specific height, so what should I do to make the tie match what I enter?i really appreciate you helping me :)
Last edited on
col. You'll need to tinker with the other variables though to make it look like a bow tie.
I'm so sorry and I know it's a pain, but I'm playing around with the variables and I'm crashing, is it possible you to explain to me, where I should change it?
I don't see how it's possible for this program to crash. Unless you mean it runs indefinitely, but that can't be the case either if you didn't touch ++row and ++col.

Any way x controls the appearance of * on the left, y on the right. cnt controls how close the * comes together towards the middle (ie. cnt should represent the middle of the bow tie). There is only so much you can modify col before the * image deforms away from a bow tie, when that happens row must be expanded.
Topic archived. No new replies allowed.