-
> for (int j=1; j<column; ++j)
You need to vary the number of characters displayed on each line, so in some way you have to involve i in the calcuation
Say
for (int j=1; j<=column-i+1; ++j)
Also, consider using more variables (with better names) to represent the different ideas in your code
Code:
void pattern2 ()
{
char ch;
int lines;
cout << "enter character";
cin >> ch;
cout << "enter # of lines";
cin >> lines;
int nSpaces = lines - 1; // number of spaces on first line
int nChars = 1; // number of chars on first line
for ( int i = 0 ; i < lines ; i++ )
{
for ( int s = 0 ; s < nSpaces ; s++ ) cout << " ";
for ( int c = 0 ; c < nChars ; c++ ) cout << ch;
cout << endl;
nSpaces--; // one less space
nChars++; // one more character
}
}
Whilst in principle you can derive everything you need from a single variable, it can lead to some confusing looking code.