E18 pops up
An E18 error refers to a problem with the lens. Generally you receive this error if the lens is stuck, which often happens if you drop your camera while the lens is extended or if something like sand or dirt gets inside the lens barrel/gears. Your situation, however, sounds different since the lens seems to extend before giving the E18 error.
If the lens is fully extending before giving the E18 error, you most likely have a problem with the lens sensor located around the O-ring inside your lens barrel... either the sensor itself is damaged or the little plastic piece on the O-Ring that triggers the sensor is broken. If that's the case, there is nothing you can do yourself unless you feel like taking apart the entire camera and finding a replacement piece.
If the lens only comes out a little bit and is not fully extending before giving the E18 error, it sounds like something is making your lens get stuck. If you've recently been to the beach or a park where there is sand, try using a can of compressed air and blow it into the little gaps in the lens barrel... you may be able to blow the sand/dirt out, solving your problem. If the air doesn't work and you feel comfortable taking apart your camera, you can get to the gearbox and manually retract the lens by following my instructions below. Otherwise, I'd suggest a repair shop.
WARNING: TAKING APART YOUR CAMERA VOIDS THE WARRANTY AND CAN BE DANGEROUS! The capacitor that charges the flash can still hold enough voltage to give you a massive shock even when the battery has been removed for some time. Please only attempt to disassemble the camera if you feel comfortable doing so. I accept no liability for anything that happens should you follow my instructions below.
In order to open the camera you will need to remove six screws on the outer casing (2 where the wriststrap ties on, 2 on the opposite side, and 2 on the bottom). After unscrewing all 6 screws, pull the back and front casings off from the bottom out, as there is a clip-hinge on the top next to the shutter button that needs to disengage before you can fully remove the casing. Once the casing is removed, there is one screw holding in the flash apparatus, on the side. Remove it and carefully bend back the metal cage around the flash apparatus and pull it up. The flash will still be attached to the camera with a pair of wires (yellow and black) and a ribbon cable... leave those in place. Please be CAREFUL when handling the flash because the capacitor (the big black thing under the flash) can hold enough voltage to give you a severe shock even with the battery removed. Underneath where the flash was you will see a multi-tiered black piece of plastic... this is the gearbox cover. Remove the three screws from the cover and carefully lift the cover off the gearbox. Inside will be a motor shaft and 4 gears (2 white, 2 black). Remove the BIG black gear closest to the lens. Then temporarily replace the gearbox cover. With the big black gear removed, the lens should freely glide in and out if you push or pull on it. Do this several times in order to clean out any gunk that may have gotten into the grooves of the lens barrel. Then, open up the gearbox, replace the black gear, and screw the gearbox cover back on. Replace the flash into the metal cage and screw it back in. Finally, put the metal outer casing back on the camera and, before screwing it in, try to turn it on. Hopefully it will work again and you can screw everything back in. If not, your problem will require significantly more disassembly.