I'm sure there are prettier ways to do it but this gets it done
Code:
#include "stdafx.h"
#include <windows.h>
#include <iostream>
using namespace std;
void Print( int, int );
int main()
{
int nEnd;
cout << "Please enter odd 1-19: " << flush;
cin >> nEnd;
Print( 1, nEnd );
return 0;
}
void Print( int nStart, int nFinish )
{
//only print for odd numbers
if( nStart%2 )
{
//for every odd number go to start (start is a bad name... oh well)
for( int i = 1; i <= nStart;i++ )
{
cout << "* ";
}
cout << endl;
}
//recurse and grow the start
//until its gets to the end
if( nStart < nFinish )
Print( ++nStart, nFinish );
//as we unwind the stack
//only allow even numbers
if( !( nStart%2 ) )
{
//even numbers and j<nStart (start-1) will keep us 2 less than above
for( int j = 1; j < nStart;j++ )
{
cout << "* ";
}
cout << endl;
}
}