All pastes #2081606 Raw Edit

Miscellany

public text v1 · immutable
#2081606 ·published 2011-09-20 17:24 UTC
rendered paste body
	// Address the 2-D integer array containing the magic square values.  No initialization is needed here.
	int n, m;
	int **square;

	try // Checking if the columns are too much memory
	{
		square = new int*[size];
	}
	catch (...)
	{
		cout << "Not enough memory!" << endl;
		delete[] square;
		square = NULL;
		return 2;
	}

	for (n = 0; n < size; n++)
	{
		try // Checking if the rows are too much memory
		{
			square[n] = new int[size];
		}
		catch (...)
		{
			cout << "Not enough memory!" << endl;
			for (m = 0; m <= n; m++)
			{
				delete[] square[m];
				square[m] = NULL;
			}
			delete[] square;
			square = NULL;
			break;
		}
	}

	if ( n < size )
	{
		return 2; // Exit if the for loop was broken.
	}