> for(c=1; c<=(2*k-1); c++)
You're not being charged by the byte for your storage, so start using meaningful names for things.
Also, stop trying to write the program without a clear understanding of the underlying pattern.
Before you even begin to type any code at all, you need to complete dhayden's table to include the pluses column.
Then you write the code to generate that table - nothing more, nothing less.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include<iostream>
using namespace std;
int main()
{
cout << "Enter number of rows (for diamond dimension) : ";
int nRows;
cin >> nRows;
for ( int row = 0 ; row < nRows ; row++ )
{
int numDashes = row; // was (2*k-1)
int numHashes = row;
int numPluses = row;
cout << row << " "
<< numDashes << " "
<< numHashes << " "
<< numPluses << endl;
}
}
|
This is the hard part, just getting the maths right.
You need to study the patterns, and fix lines 10,11,12 to regenerate the table you crafted by hand on paper.
If you can do that, you're done with the hard work.
It's plain sailing after that.
1 2 3 4 5 6 7 8
|
for ( int row = 0 ; row < nRows ; row++ ) {
printSomeChars(numDashes,'-');
printSomeChars(numHashes,'#');
printSomeChars(numPluses,'+');
printSomeChars(numHashes,'#');
printSomeChars(numDashes,'-');
cout << endl;
}
|
Where
1 2 3
|
void printSomeChars(int n, char c) {
for ( int i = 0 ; i < n ; i++ ) cout << c;
}
|