I'm having trouble outputting this file.
This is how it comes out.Code:#include <fstream.h> #include <stdlib.h> #include <iomanip.h> int n; // dimension size ofstream outfile; // create square to set all digits to 0 void square(int box[17][17], int row, int column) { for(row = 0; row < 17; row++) { for(column = 0; column < 17; column++) box[row][column] = 0; } } int size() { // ask user for size cout << "Enter size between 3 and 15(ODD): "; outfile << "Enter size between 3 and 15(ODD): "; cin >> n; outfile << n; { while(n < 3 || n%2==0) { cout << "Enter size between 3 and 15(ODD): "; outfile << "Enter size between 3 and 15(ODD): "; cin >> n; outfile << n; } { return 0; } } } // assign #'s void sort(int box[17][17], int row, int column, int value) { // outer numbers for(row = 0; row <= n; row++) { box[row][n+1] = -3; } for(column = 0; column <= n; column++) { box[0][column] = -1; } box[0][n+1] = -2; column = (n+1) / 2; row = 1; // inner numbers for(value = 1; value <= n * n; value++) { switch(box[row][column]) { case 0: box[row][column] = value; break; case -1: { row = row + n; box[row][column] = value; break; } case -3: { column = column - n; box[row][column] = value; break; } default: { row = row + 2; column = column - 1; box[row][column] = value; break; } } row--; column++; } } // print out square void print(int box[17][17], int row, int column) { for(row = 0; row < n + 2; row++) { for(column = 0; column < n + 2; column++) cout << setw(3) << box[row][column] << " "; outfile << setw(3) << box[row][column] << " "; cout << endl; outfile << endl; } } int main() { outfile.open ("project6.txt", ios::out); int box[17][17]; // dimension of square int row = 1; int column = 2; int value = 1; square(box,row,column); size(); sort(box,row,column,value); print(box,row,column); system("pause"); return 0; }
Any suggestions would be appreciated. Thanks.Code:Enter size between 3 and 15(ODD): 1Enter size between 3 and 15(ODD): 2Enter size between 3 and 15(ODD): 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1242328



LinkBack URL
About LinkBacks


