Writing formulas for ionic compounds