I assume by acute you mean equilateral. It's terribly difficult to get all of the acute trianglesto print accurately using command line output. Instead of one nested loop, try two. The first nested loop should handle spaces and the second should handle asterisks:
for i = 0 to N do
for j = 0 to spaces do
print ' '
for j = 0 to stars do
print ' '
print '\n'
Then you only need to work out the initial values for N, spaces, and stars, as well as how to modify spaces and stars to get the output like you want it.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Before saying anything else, I want to be sure that you know the code I posted is not C++. ;) It's pseudocode, meant to express an algorithmic concept and be easily translatable into any imperative programming language.
>Im going to have to declare the N, spaces, stars, right?
Yep. N is the height of the triange, so if N is 5, the triangle should look like this:
*
***
*****
*******
*********
spaces is the number of whitespace characters printed before the line of asterisks, and stars is the number of asterisks to print. In the above example, spaces starts at 4 and counts down, stars starts at 1 and counts up by two.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Here's the pseudocode translated to C++. All you need to do is figure out what initial values to give spaces and fills, and what changes to make with each iteration. That's most of the problem anyway.
int n = 5;
int spaces = // You need to figure out
int fills = // You need to figure out
for (int i = 0; i < n; i++) {
for (int j = 0; j < spaces; j++)
cout<<' ';
for (int j = 0; j < fills; j++)
cout<<'*';
spaces = // You need to figure out
fills = // You need to figure out
}
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Well, okay. If you wanted to do it the fun way, why didn't you say so? Nested loops are so 1995:
#include <iomanip>
#include <iostream>
using namespace std;
int main()
{
int n = 5;
for ( int i = 0; i < n; i++ ) {
cout<< setfill ( ' ' ) << setw ( n - i - 1 ) <<"";
cout<< setfill ( '*' ) << setw ( i * 2 + 1 ) <<""<<endl;
}
}
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>sorry i forgot to put comments in my code ..... guess i was of no help at all, huh ?
No, you forgot to put code tags around your code. Comments aren't needed if the code is self documenting, and code with no indention is far from self documenting.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401