Tuesday, July 28, 2009

C++ fractals HELP!?

Ok, got this to semi-work. It is supposed to print fractals. Can anybody tell me what i'm doing wrong this time? haha








#include %26lt;iostream%26gt;


using namespace::std;





using std::cout;





void pattern(int nstars, int startcol);





int main()


{


pattern(16,0);


return 0;


}





void pattern(int nstars, int startcol)


{


if (nstars == 1)


cout %26lt;%26lt; "* " %26lt;%26lt; endl;


else


{


pattern(nstars/2,startcol);


for(int k=0;k%26lt;startcol;k++)


cout %26lt;%26lt; " ";


for(int k=0;k%26lt;nstars;k++)


cout%26lt;%26lt; "* ";


pattern(nstars/2,startcol);


}





}

C++ fractals HELP!?
startcol is passed in 0





in the for loop k goes until k%26lt;starcol which is 0, so it never goes through the loop. Try





pattern(16, 20) in the main


No comments:

Post a Comment