Nicolla MacPherson wrote:
Hi
I'm a newbie and want to display a pattern that will increment with each
line of display.
what pattern?
I thought i might be able to count the rows and use that info to increment
my display.
You might. It depends on the pattern.
I've got my starting point using setw and don't want to use cout for every
line of display. What should i be looking for to use.
Using cout for every single line is the easiest thing you could do, *if*
your pattern is that way. It all depends on what the pattern looks like.
If your pattern is such that you can derive some formula from the line count,
then things are going the easy way.
Example: You have to produce this pattern:
*
***
*****
*******
*********
So what do you recognize? Every line consists of spaces followed
by '*' characters. How many are in each line? Lets make a table:
line # | # of spaces # of asteriks
---------+-----------------------------
0 | 5 1
1 | 4 3
2 | 3 5
3 | 2 7
4 | 1 9
Now can you come up with some formulas that emit the
number of spaces when given the line number? What about
the number of asteriks?
#_of_spaces = 5 - line_#
#_of_asteriks = 2 * line_# + 1
So your output loop basically looks like this
for( line = 0; line < 5; ++line )
{
compute NrOfSpaces as 5 - line
compute NrOfAsteriks as 2 * line + 1
output NrOfSpaces ' '
output NrOfAsteriks '*'
output '\n'
}
And thats it for this specific pattern.
--
Karl Heinz Buchegger
kb******@gascad.at