You may have used the definition of cosine, but did not use the Pythagorean Theorem to find h:
After solving this equation, substitute the value of h for the hypotenuse in the definition of cosine.