2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Clinton Portis
0

This should give ye' at least an idea. I'll draw half of the hexagon, ye' can do the rest. This is untested, but feel free to tweak it as necessary to draw that perfect hexagon:

#include<iostream>
#include<iomanip>

void draw_hex()
{
     //Draw Top
     cout << setw(10);
     for(int i=0; i<5; i++)
     {
          cout << '*';
     }
     cout << endl;

     //Draw Top Sides
     int left_offset = 10, right_offset = 5;
     for(int i=0; i<5; i++)
     {
          cout << setw(--left_offset) << '*' << setw(right_offset+=2) << '*' << endl;
     }

     //Draw Bottom Sides
     ...
     ...
     ...
     //Draw Bottom
     ...
     ...
     ...
}

Edited by Clinton Portis: n/a

0

oh sorry i forgot to mention...v r only to use for loops and ony iostream.h

sorry i didnt mention it before

0

I would then suggest maybe trying a char hex[20][20] array. (This will be a char[row][column] 20x20 square array).

Initialize all the array elements to a white space:

for(int i=0; i<20; i++)
     for(int j=0; j<20; j++)
     {
          hex[i][j] = ' ';
      }

Now I would suggest using a piece of graph paper and figure out what elements ye' would like to populate to draw a hexagon.

hex[3][10] = '*';
hex[4][11] = '*';
hex[5][12] = '*';
hex[6][11] = '*';
...
...
etc etc.

Now you can draw your entire hexagon with one nested for loop:

for(int i=0; i<20; i++)
{
     for(int j=0; j<20; j++)
     {
          cout << hex[i][j];
     }
    
     cout << endl;
}

Edited by Clinton Portis: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.