samedi 23 septembre 2017

Star Pattern coding C++

So as a homework assignment we were assigned to build a code that outputs a pattern similar to the British flag. I think I started off really good, however, i am stuck and have no idea how to proceed. This is what I have so far...

////////////////UPPER 2 QUADRANTS//////////////////////////////   


for (int i = 0 ; i < 10; i++)
{
cout << " 1";

if(i==0){
  for(int h=0;h<20;h++) cout<<" 2";
  cout<<" 3";
}

if(i==9){

  for(int k=0;k<20;k++) cout<<" 4";  
  cout<<" 5 ";
}


for (int j = 0; j < 20; j++)
{
  cout << "  ";

  if(i!=0&& i!=9 && i!=0&& i!=19 ){
  if(j==9 || j==19)

  cout<<"6";
  }

}

cout << endl;

 }
////////////////LOWER 2 QUADRANTS//////////////////////////////

for (int i = 0 ; i < 10; i++)
{
cout << " 1";

if(i==0){
  for(int h=0;h<20;h++) cout<<"  ";
  cout<<" 3";
}

if(i==9){
  for(int k=0;k<20;k++) cout<<" 4";  
  cout<<" 5 ";
}


for (int j = 0; j < 20; j++)
{
  cout << "  ";

  if(i!=0&& i!=9 && i!=0&& i!=19 ){
  if(j==9 || j==19)

  cout<<"6";
  }

}

cout << endl;

  }



   return 0;
 } 

My code outputs numbers because it is easier for me to format it so I know what each line of code is doing. Now my question is, how would I be able to format what I have now to implement the diagonal pattern in all the 4 quadrants?

Aucun commentaire:

Enregistrer un commentaire