The object is to create a diamond with an odd number of rows, the range being from 1 to 19, and I did that, but I need help understanding why it works.
Through this question being asked so many times on this and similar c++ forums, I found the code to help me complete my assignment. That's good and everything, but I want a deeper and more intuitive understanding of why.
#include <iostream>
using namespace std;
int main ()
{
cout << "Enter an odd number from 1-19: " << endl;
int n=0;
int i=0;
int z=0;
cin >> n;
if (1==n%2 && 1 <= n && 19 >= n){
cout << "Thank you for the valid entry! Here is your diamond." << endl;
for (i=0; i<n; i++)
{
for (z=0; z<=n-i; z++){
cout << " "; }
{cout << "That is not an odd number and/or in the domain. Have a great day!" << endl;
system ("PAUSE");}
}
I wrote all of this, but the diamond section is an amalgamation of a couple different answers I seen online. But anyways, how the hell does this end up making a diamond? I would've never thought of it; so darn unintuitive. PS sorry for the bad code :( ; just started programming a couple of weeks ago.