Why does my iPhone switch off even tho there's still battery life?

It's the third time it's happened, what can you do to fix it? Has it happened to anyone eles?

Yes it happened to me before on my iphone 4 but i don't know if everybody has the same problem because lots of things can cause this… I fixed mine because one day i opened the back of my phone and i noticed a screw was missing from the metal part that holds the battery ribon in place so every time i would shake my phone really hard it would turn off… But if your iphone is new or hasent every been opend then i don't think thats the problem but it might be… Sometimes it happened to my phone even thow i wasn't usung it but after i put the screw back in it never happened again.

I think it's a battery-related problem. ITry seeking help from a qualified technician.