okay, i am starting from scratch again....
here's my specifics for the square:
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. Your program should "trap" incorrect input and issue the appropriate error message. Create a formatted input file with the following data: 1 19 12 3 9 15 .
It is never said whether one large square should be made or multi
little ones. I don't even care at this point, I'd just like to understand how to make ONE.
I can get the numbers from the ext file in...decide whether they meet MSquare criteria, but that's it.
I've tried to write my own code to build the square..follow others algorithms..which are confusing because there's so many...
and i can't even get ONE source to compile.
(I am already a week begind with this and can't even get myself thru the basics)...I will need to assign functions to the code eventually, but i figured i better be able to run it first.
I really WANT to understand it, but I am just getting more and more frustrated.
Any pointers would be appreciated....
i am trying to have the code do this:
*Place the number 1 in the middle column of row 1.
*From this starting position (original position) go up one cell and to the
right one cell and place the next integer in that cell. If moving up forces
you out of bounds, wrap around and continue from the corresponding
cell in the bottom row.
*Do the same thing if you go out of bounds when moving right.
*If the cell you are moving to has already been filled, drop down one cell
from your original position and place the integer there instead.
*Do this until all the cells are filled.
PLEASE help...I don't want anyone to write it for me,
but I am so stuck frustrated.\
Thanks alot...
this is the last workable thing I've gotten to...
(and the sum doesn't even work!)
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("A:\\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("A:\\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 : "<< count << "\n" << endl;
if (count > 1 && count < 17 && count%2 != 0){
outfile << "make sqare here" << "\n\n";
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;
}
Michele