hi , can someone please look at the source of my frustration:?
I am having probs with my magic sq program...
it is taking 6 numbers from an external file and determining whether they fit the criteria and if so calculating the sum of the magic square it makes..
not sure if i am supposed to make ONE lareg square with the biggest working odd number or a bunch of little ones...
eventually i will assign fuctions to different prts of the program but ai am stuck at this part-
anyway i can't even get one to print out please look:
Code:#include<iostream> #include<iomanip> #include<fstream> #include<cmath> using namespace std; const int SIZE = 17; int square[SIZE][SIZE]={0}; const int RANGE = (SIZE*SIZE); ofstream outfile("C:\\1107OFZZZ.txt"); int main () { if(!outfile){ cerr << "Cannot open output file" << endl; return 1; } int count=0; int cols=0; int row=0; //build the magic square ifstream infile("C:\\1107IF.txt"); if(!infile){ cerr << "Cannot open input file" << endl; } outfile << "\n Magic Criteria: Write a program which prints out a magic square as well as its magic sum, for an odd integer s greater than 1 but less than 17.\n\n"; while (infile >> count){ bool f = true; if (bool f= true){ outfile<< "\nMagic Number is "<< count << "\n" << endl; if (count > 1 && count < 17 && count%2 != 0){ //make square here: //---------------------------------------------------------------- cols++; if(row == -1 && cols == SIZE){ row+=2; cols--; } else if (row == -1) row=SIZE-1; else if(cols == SIZE) cols = 0; else if (square[row][cols] != 0){ row+=2; cols--; } square[row][cols] = count; while (count < RANGE){ //print magic square for(row=0;row<SIZE;row++){ for(cols=0;cols<SIZE;cols++){ outfile <<square[row][cols]<< setw(3); outfile <<"\n"; }//while }//for }//for //----------------------------------------------------------------------end of square int sum = 0; for (cols = 0; cols < count ; cols++) // down column 2 sum += square[0][cols]; outfile << "Sum of Magic Number" << count <<" = " << sum <<"\n" << endl; outfile << "+-------------------------------------------------+" << "\n\n"; }//if else {outfile << "Number does not fit magic Criteria\n"<< endl; outfile << "+-------------------------------------------------+" << "\n\n"; bool f= false; }//if }//bool }//while return 0; }
[code][/code]tagged by Salem
Didn't help - its not indented to start with



LinkBack URL
About LinkBacks


