Can't reinstall Mac OS X I have an old Mac and OS X won't start, it is stuck loading the OS.

I want to reinstall but it just ejects the DVD a few seconds after I put it in.

The Mac has an i5 3.1GHz CPU and 4GB 1333 MHz DDR33 RAM.

I don't know a lot about Apple computers, I mainly use Windows; any help would be appreciated.
shut down the mac, boot it up in Recovery mode, CMD + R, go to disk utility, select your main disk, and erase it, format it as Mac extended, 
close that window, go to Reinstall MAC OS X, and then follow the instructions, thats the best, way to re-install, it will never go wrong.