Hey guys iv made a program that makes diamond shape appear. It works fine
and the image is perfect. But I was wondering, I have broken the code into two
sections, the top and bottom half the shape. Is it possible to use a single loop
of deep nested for loops to make the shape appear any different and more cleaner than I have done?
All im looking for is pointers on my coding...
Code:#include <iostream> // main function - begins program execution //////////////////////////////////// // int main ( void ) { int spaces, stars; // top hslf of diamond for ( int line = 1; line <= 5; line++ ) { spaces = abs ( line -5 ); for ( int loop = 1; loop <= spaces; loop++ ) std::cout << " "; stars = line + ( line -1 ); for ( int loop = 1; loop <= stars; loop++ ) std::cout << "*"; std::cout << std::endl; } // bottom half of diamond for ( int line = 1 ; line <= 4; line++ ) { spaces = line; for ( int loop = 1; loop <= spaces; loop++ ) std::cout << " "; stars = 9 - 2 * spaces; for ( int loop = 1; loop <= stars; loop++ ) std::cout << "*"; std::cout << std::endl; } std::cin.get(); // freeze console output window return 0; // return value from int main }