Hello everyone. I am new to the site and have a question. I am trying to write a descending triangle program with asterisks in C++. I have everything working but my output is not centered correctly and it is driving me nuts. I have played with variables and the loops and I just can't get it. Any help would be appreciated. Here is what I got for code:
On the first line, you want 0 spaces and N asterisks? Then
On the second line, you want 1 space and N-2 asterisks.
On the third line, you want 2 spaces and N-4 asterisks.
Look for the pattern.
There is no need for division or floating point arithmetic in this program.
Thanks for the input jsmith.
I want the output to have 1 asterisk on the bottom line, 3 asterisk's on the second line, 5 asterisk's on the third up to N lines. I need to increment the asterisk's by 2 each loop but I can't figure how. I have change and/or incremented every variable but no luck. I am about to move on to something different.
Any advice? - besides moving on to something different :) -
Thanks again
Since your program must output the top line first, you should think about it the
way I wrote above ... first line first.
If you want N lines of output, then on the first line (line zero) there will be 0 leading
spaces followed by ( N - 0 ) * 2 + 1 asterisks. On the second line (line one) there will be
1 space followed by ( N - 1 ) * 2 + 1 asterisks.
You'll want one big loop that counts the number of lines output so far (N in my above
formulas). Inside that loop, you'll need two independent for loops: the first one will
output the correct number of spaces, and the second will output the correct number
of asterisks.
This should be everything you need. I can't give you any more hints without actually
writing the code for you. Why don't you try implementing what I wrote and post your
code if you aren't able to get it working.