Hiya. I have this program that gives me alternating squares that switch from full squares to hollow. The problem I am having is that the squares that should be hollow are showing up with numbers in them like this. Anyone know what my problem is?
***
***
***
0000
1111
2222
3333
*****
*****
*****
*****
*****
000000
111111
222222
333333
444444
I'm trying to make it look like this.
***
***
***
****
* *
* *
****
*****
*****
*****
*****
*****
******
* *
* *
* *
* *
******
#include <iostream>
using namespace std;
void alternatingSquare(unsigned n);
void square(unsigned a);
void hollowSquare(unsigned a);
int main(){
for (unsigned size = 3; size <= 6; ++size)
alternatingSquare(size);
cout << endl;
system("pause");
return 1;
}
void alternatingSquare(unsigned n){
static bool solid;
((solid=!solid) == true ? square : hollowSquare) (n);
}
void square(unsigned n){
for(unsigned i = 0; i< n; ++i){
for(unsigned j = 0; j< n; ++j)
cout << '*';
cout << endl; }
}
void hollowSquare(unsigned n){
for (unsigned i = 0; i < n; ++i){
for(unsigned j = 0; j < n; ++j)
cout << i ==0 || i==n-2 || j==0 || j==n-1 ? ' ' : '1';
cout << endl;
}
}