1 2 3
|
(i=0);
(triangle=0);
(k=0);
| |
You don't need to parentheses around these assignments.
for (int triangle = 0; triangle > 3; triangle++) {
This loop will never execute. In English, you're telling the computer:
"Set triangle to zero. Now if triangle is greater than three, execute this loop". Since the initial value of triangle is zero, and zero is NOT greater than 3, the loop never executes.
for (k=1 ; k=size ; k++)
k=size
is wrong for 2 reasons. First,
=
is the assignment operator.
==
is the comparison operator. But in this case, I think you want
k!=size
. Otherwise the loop will execute forever.
Is this what it's supposed to look like?
$ ./foo
please enter the size of the triangle 6
*
* *
* *
* *
* *
**********
$ ./foo
please enter the size of the triangle 4
*
* *
* *
****** |
To write code for this, I put a comment in the code with an example of the output. I labelled the lines with the number of spaces. This helped determine the loops:
1 2 3 4 5 6 7
|
// Example for size = 5
// 012345679
// 0 * 1 star
// 1 * * 1 space
// 2 * * 3 spaces
// 3 * * 5 spaces
// 4 ******** 8 stars
| |