Hexagon not printing out right
Nov 4, 2012 at 11:57pm UTC
Hey guys so i finished my program and i decided to try to improve a few flaws it has, one of which is that when using an odd number my vertical lines match up but not when using an even number.
So i was wondering if someone could point out where im going wrong,
heres my function it works fine other then the alignment problem.
i tried to sort it by checking if the size inputted is odd or even then printing out the lines accordingly, but that dosn't seem to work.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
void Vertical(int sizeInput, int type)
{
//spacer stores spaces to be used to properly space hexagons and add gaps inside them
//counter stores number of iterations that have currently passed so inside spaces get placed properly
string spacer = " " ;
int counter =0;
fill = "|" ;
cout << "Type " << type << endl;
int rows = 0;
for (; rows < size+1;rows++)
{
if (rows==0)
{
for (int spaces = 1+size; spaces > rows;spaces--)
{
cout << spacer;
}
for (int tops = 0; tops < size;tops++)
{
cout << "_" ;
}
cout << endl;
}
else
{
for (int spaces = 1+size;spaces > rows;spaces--)
{
cout << spacer;
}
cout << "/" ;
for (int stars=0; stars < size + ((rows - 1) * 2);stars++)
{
//checks if current iteration is even and if type is 4
//if so prints a spacer instead of the filler
if (size % 2 == 0)
{
if (counter % 2 == 0)
{
cout << spacer;
counter++;
}
else
{
cout << fill;
counter++;
}
}
if (size % 2 != 0)
{
if (counter % 2 == 0)
{
cout << fill;
counter++;
}
else
{
cout << spacer;
counter++;
}
}
}
cout << "\\" ;
cout << endl;
}
}
//empties counter value so iteration count is reset
counter = 0;
for (; rows >= 2; rows--)
{
if (rows == 2)
{
for (int spaces = 2+size;spaces > rows;spaces--)
{
cout << spacer;
}
cout << "\\" ;
for (int bottoms = 0;bottoms < size;bottoms++)
{
cout << "_" ;
}
cout << "/" ;
cout << endl;
}
else
{
for (int spaces = 2+size;spaces > rows;spaces--)
{
cout << spacer;
}
cout << "\\" ;
if (size % 2 == 0)
{
for (int stars=0; stars < size + ((rows - 2) *2);stars++)
{
if (counter % 2 == 0)
{
cout << spacer;
counter++;
}
else
{
cout << fill;
counter++;
}
}
}
if (size % 2 != 0)
{
for (int stars=0; stars < size + ((rows - 2) *2);stars++)
{
if (counter % 2 == 0)
{
cout << fill;
counter++;
}
else
{
cout << spacer;
counter++;
}
}
}
cout << "/" ;
cout << endl;
}
}
rows =0;
counter = 0;
}
thanks in advance, also this is my assignment but i've done the actual assignment now im just finetuning it.
Topic archived. No new replies allowed.