Quote Originally Posted by 2kaud View Post
If you are using Windows 7 why don't you use the free Microsoft Visual Studio Express 2013?
See http://www.visualstudio.com/download...sual-studio-vs
You want Visual Studio Express 2013 for Windows Desktop.

As I suggested in my post #17, before you continue with 'ad hoc coding' of the program, I recommend that you take a step back and design the program before you try to code it.
Code:
for (i < LatSize) {M+= matrix[i][j];}
This is not valid c++ code. You also can't initialise a variable when it is defined within a class definiton (unless it is static of an integral type). If you want M to be the sum of the matrix values then you could code it as below. From your original code, B should also defined as 1?

Based upon what I understand from your postings, this is a possible program so far
Code:
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;

const int LatSize = 5;

class cSpin
{
public:
	cSpin() : M(0)
	{
		for (int i = 0; i < LatSize; i++) 
			for (int j = 0; j < LatSize; j++)
				M += matrix[i][j] = (rand() % 2) * 2 - 1;
	}

	int& operator()(int x, int y)
	{
		if (x < 0)
			x += LatSize;

		if (x >= LatSize) 
			x -= LatSize;

		if (y < 0) 
			y += LatSize;

		if (y >= LatSize)
			y -= LatSize;

		return matrix[y][x];
	}

	void display()
	{
		for (int i = 0; i < LatSize; i++)  // loop 3 times for three lines
		{
			for (int j = 0; j < LatSize; j++)  // loop for the three elements on the line
				cout << setw(2) << matrix[i][j] << " ";  // display the current element out of the array

			cout << endl;  // when the inner loop is done, go to a new line
		}
	}

	int SpinSum()
	{
		return M;
	}

private:
	int matrix[LatSize][LatSize];
	int M;
};

int main()
{
const int J = 1;
const int B = 1;

cSpin	spin;

	srand (static_cast<unsigned> (time(0)));

	spin.display();

int M = spin.SpinSum();

int x = int (rand() % LatSize); 
int y = int (rand() % LatSize);

int neighbour = 0;    // nearest neighbour count
int flip_counter = 0;
double sweep_counter = 0.0;

	for (int i = 0; i < LatSize; i++)
		for (int j = 0; j < LatSize; j++)
		{
			neighbour += (spin(i, j) == spin(i + 1, j)) ? 1 : -1;
			neighbour += (spin(i, j) == spin(i, j + 1)) ? 1 : -1;
                }

int E = -J * neighbour - B * M;

int delta_M = -2 * spin(x, y);	//change in magnetization energy

int delta_neighbour = delta_M * (spin(x - 1, y) + spin(x + 1, y) + spin(x, y - 1) + spin(x, y + 1)); 

int delta_E = -J * delta_neighbour - B * delta_M;

	if (delta_E <= 0)
	{
		spin(x, y) *= -1;											// flip spin
		M += delta_M;												// New Magnetization energy of flipped configuration
		E += delta_E;												// New total energy of flipped configuration
		flip_counter++;												// Total number of sites chosen up till this point
		sweep_counter = (double)flip_counter / (LatSize * LatSize);	//Total number of sweeps till this point
	}
	else
	{
		//if flipped, M and E is updated. If not flipped, M and E is unchanged.
	}

	cout << "The site chosen is at (" << x << ", " << y << ") = " << spin(x, y) << endl;
	cout << "The left neighbour has spin = " << spin(x, y - 1) << endl;
	cout << "The right neighbour has spin = " << spin(x, y + 1) << endl;
	cout << "The above neighbour has spin = " << spin(x - 1, y) << endl;
	cout << "The below neighbour has spin = " << spin(x + 1, y) << endl;
	cout << "The change in neighbour energy = " << delta_neighbour << endl;

	return 0;
}
I hope this helps. But you really need to do some design work for the program before you continue coding. Also I would suggest that you become more familar with the c++ language. What book(s) are you using from which to learn c++?
Hmm now when I run the program, the neighbours of (x,y) give the wrong values, I think something is wrong with the boundary conditions. Also, for a 3x3 matrix, the value of M (Sum of all spins) are wrong..

To be honest, this program is nearly complete! Once the sum of all spins, 'M' can be properly calculated and displayed and the flipping decision is done, this program is finished.

At the moment, I'm overloaded with coursework as well but I still want to finish this program and understand it.
Is there any section of C++ you would recommend to understand this program? Don't get me wrong, I find programming to be extremely useful and would definitely study it in greater detail but at the moment I'm quite tied up...