Valence shell electron repulsion theory is the theory that explains the shape of simple molecules.

Electrons are all negatively charged and therefore repel each other. Because of this, electrons want to be as far away from each other as possible. Electrons also have a tendency to group themselves into pairs. You don't often have electrons that are by themselves because it's not as stable.

OK! Lets take a look at BeF2:

                           F--Be--F

The central Be atom has two electron pairs in its valence energy level after forming a covalent bond with each F atom. The two electron pairs achieve maximum separation by taking up positions on opposite sides of the central atom. The shape of BeF2 is therefore linear.

What am I talking about? This should explain it a bit better: BeF2's electron dot diagram looks like this:

              ..    ..
             : F;Be;F :
              ..    ..

the ';'s represent a bonded pair of electrons. So the Be has those two bonded electron pairs that repel each other. The rest of the electrons don't really matter as much. (However, you must remember that a lone pair of electrons still repels strongly, just not as strongly.)
So those paired electrons will repel each other and the molecule will take on the following structure:

                .,
            F - Be - F
                .,

The reason being that the electrons are now as far away as possible from each other.
Lets look at water as another example. When the H+ gets with the O-2 the electron dot diagram looks like this:
              .H,
             :.O.;H

As you can see, in the water molecule there are two lone pairs of electrons that will repel the bonded pairs. The arrangement of atoms will result in a V shape.
               ..
             H-O :
               |
               H
That is roughly how water looks but the angle between the H-O bonds is larger (104.5 degrees).

So to find the shape of an atom you must consider the following:
1) How many bonded pairs of electrons there are
and
2) How many lone pairs there are
And remember that lone pairs don't repel quite as strongly as bonded pairs.
Once you have determined what is being repeled you can easily determine where atoms need to go to repel each other the least.

See also:
A guide to the shapes of molecules

Information mainly from my chemistry teacher, Dr Plewright, and my Foundations of Chemistry text book