hi i am a beginner in c++ and have these shapes( in the attached word doc) to do using for the for the first set for loops, the second while loops and the third set do while loops. i already have done the first 2 shapes with this code:

#include <stdio.h>
void main()
{
 int row, a1, a2, a3, a4, a5;
 for (row = 1; row <= 5;  row++)   // generate the rows
 {
 
  for (a1 = 1; a1 <= row; a1++)  // generate the column stars
  {
   printf("* ");
  }
  for (a2 = 1; a2 <= 5 - row; a2++) // generate the remaining box
  {
   printf("  ");
  }
  printf("\t");      // tab between shapes
 
  for (a3 = 5; a3 > row; a3--)   // generate the leading spaces
  {
   printf(" ");
  }
  for (a4 = 1; a4 <= row; a4++)   // generate the column stars
  {
   printf("* ");
  }
  for (a5 = 5; a5 >= row + 1; a5--)  // generate the remaining box
  {
   printf(" ");
  }
  printf("\n");      // start next row
 }
 printf("\n\n");
}

but now i have no idea on how to do the others? hope someone can help thanks

First of all

1. Indent your code properly so that it is easy for us to go through it.

2. Dont use void main( ) , use int main ( ).

3. You have very much accomplished most of the task, but I think the mistake you are doing in your case is to put all the things together.

FOr eg. I can see in your code that you have generated both the shapes using the same for loop. It would be a very good idea to make your each and every shape generation distict and modular, since all the other shapes are just derivates of the first two.

Make your code into something like:

int main ( )
{
   // generate the first shape seperately
   for( .... ) 
   {
    // logic for first shape
    }

   // generate the second shape
   for ( ... )
  { 
   // logic for second shape
   }
}

OR

int main ( )
{
    generate_first(dimensions_for_the_shape ) ;

    generate_second(dimensions_for_the_shape ) ;
}

This way, you would need to do less rewriting and the logic is greatly simplified.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.