You can only meet force with force
In a purfect world you would pull your gun and shoot him in the head, dead (the bad guy). But can you be sure you will kill the bad guy, will his reflexes cause his hand to tighten and the the poor man behind the counter is dead. He has a wife and 3 children at home, are you able to explane to them why there dady is dead.
A gun is a terrable responsibility, It can save a life by taking another, but it can also turn a simple robbery into a mass killing.
Your question is a good one with many answers. But the person that says "I'm going to pull my gunout and pop him in the head" is a person that probably souldnt be carring a gun.
What I would do is just stand there, and let things run there corse.
But if the bad guy started pulling the trigger, I would do everything in my power to see that no one got killed and then live with the results.
I have only pulled a gun on one person in my life, he had stollen my neighbors car. I caught him that night at a gas station and held him at gun point untill the poliece arived.
My neighbors son asked "Would you have shot him if he had took off running?"
My answer dissipointed him, " He was younger than me and in a lot better shape, I would have waved goodby."