your looping is incorrect.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
for (i = 1; i < 5; i++)//initial rows is 1,
//if row is less than 5, add row
{
//increasing stars
for (j = 1; j < 3; j++)//initial stars is 1
//if stars are less than 3 add star
{
cout << VIEW;
}
//begin reducing stars
for (j = 2; j < 1; j++)//initial stars is 2
//if stars are less than 1, add star
{
cout << VIEW;
}
}
|
think about exactly how this is gonna work. everything inside the 'i' loop is going to be executed 5 times. this means that the first 'j' loop is going to go through and it's going to print two *'s.
Now we come to a real problem, the second 'j' loop, is going to run for quite a while. J
starts at 2, and increments by 1 until j overflows and wraps around to a negative number, at which point you will have added several millions of *'s to your output.
then, once the two inner 'j' loops have finished, we back out to the 'i' loop again, increment 'i' to 2, and run through both 'j' loops a second time... then a third time, and a fourth time, then, finally, the i loop is done, and you've just spat out 3.7 bajillion *'s to the output stream (without ever sending a newline, btw), and the program ends.