Hello , i was doing an exercise in book which asked to draw a diamond shape by displaying '*' using nested for loops. It took me quite a while to come up with a way to reverse the pyramid , and complete this exercise. So i was hoping some one can take a look at this code and let me know what they would have done different. Thanks. Again sorry for posting on multiple forums i just value responses i get and hopefully learn something. Thanks.
//draws a diamond shape ex
/*
*
***
*****
***
*
*/
#include "stdafx.h"
#include <iostream>
using namespace std;
int main(){
int nRow, nColumn, nDiamond = 8, nCenter, nColumnSize;
nCenter = nDiamond / 2;
for ( nRow = 0; nRow <= nDiamond; nRow++ ){
nColumnSize = nRow <= nCenter ? nRow + nCenter : nColumnSize - (nCenter / nCenter);
for ( nColumn = 0; nColumn <= nColumnSize; nColumn++ ){
//checking if we at center
if ( nRow <= nCenter ) {
if ( nCenter - nRow > nColumn )
cout << ' ';
else
cout << '*';
//reversing
}else if ( nRow - nCenter > nColumn )
cout << ' ';
else
cout << '*';
}// end columns
cout << endl;
} //end rows
return 0;
}