Power supply, loose wires, the motherboard, windows service settings, or program conficts can cause it to turn off suddenly too. So can viruses. Scan, poke around for problems, if that doesn't fix it open it up and clean out any dust. Check plugs to make sure they're all in tightly. The good news, if it's something minor it's easy to replace, even the motherboard could be if the computer's a couple years old.
I hate tossing out stuff if it still works!
Even if I do replace it, you just never know when you'll need a backup comp.