I am trying to make a rotating function for a 4X4 array:
Here is what I have so far, but I need the array to be a bool functuion that displays some zeros, so far it is only displaying 1s, any ideas?
Code:#include "stdafx.h" #include <iostream> #include <string> #include "header.h" using namespace std; #define MAX_SIZE 4 void main() { bool box[MAX_SIZE][MAX_SIZE]; bool newbox [MAX_SIZE][MAX_SIZE]; int col; int row; for(int col =0; col < MAX_SIZE; col++) { cout << "Enter characters (4)" << col +1 << ":"; string s; cin >> s; /*if ( s.length() < MAX_SIZE) { for (int k = s.length(); k < MAX_SIZE; k++) s = s + " "; }*/ for(int row = 0; row < MAX_SIZE && row < s.length(); row++) { box[row][col] = s[row]; } } //print box for(int col =0; col < MAX_SIZE; col++) { for (row = 0; row < MAX_SIZE; row ++) cout << box[row][col] << " "; cout << endl; } //rotate for(int i=0; i<4; i++) for(int j=0; j<4; j++) newbox[3-j][ i ]=box[ i ][j]; /*for(int i = 0; i < MAX_SIZE; i++) { for(int j = 0; j < MAX_SIZE; j++) { newbox[i][j] = box [(MAX_SIZE -1)-j][i]; } }*/ //copy to newbox /*for(int col = 0; col < MAX_SIZE; col++) { for(int row = 0; row < MAX_SIZE; row++) { box [row][col] = newbox[row][col]; } }*/ cout << "After rotation:" << endl; //print newbox for(int col =0; col < MAX_SIZE; col++) { for (row = 0; row < MAX_SIZE; row ++) cout << newbox[row][col] << " "; cout << endl; } }