Is there another method to solve this differential equation? Here's an differential equation
$\frac{dy}{dx}+y\cos x=2\cos x $ I solved by using this way. 
 A: As others have pointed out, you used the separation of variables technique, which is usually the easiest solution. You do have some minor mistakes in your solution, however. First, you did not consider the possibility that $-y+2=0$ when you divided by $-y+2$. Second, as @KittyL pointed out, you left out the absolute value signs when you got $\ln$ from the integral. Last, the $C_1$ in your next-to-last line is not the same as the $C_1$ in your last line: you should change one of them, perhaps the last one to just $C$. If you include these things and simplify, you do indeed end up with your final answer. Many calculus classes are not very rigorous and you might be able to get away with your simplistic solution: it depends on your grader/professor.
Another method is using the integrating factor method for first-order linear ordinary differential equations. This method solves the equation
$$\frac{dy}{dx}+p(x)\cdot y=q(x)$$
In your case, $p(x)=\cos x,\ q(x)=2\cos x$. The integrating factor here is
$$m(x)=e^{\int p(x)\,dx}=e^{\int cos x\,dx}=e^{\sin x}$$
(Any integral will do: we can leave out the arbitrary constant here.) The integrating factor clearly is never zero (it never is), so we can use the general solution, which is
$$y=\frac{1}{m(x)}\int m(x)\cdot q(x)\,dx$$
$$=\frac{1}{e^{\sin x}}\int e^{\sin x}\cdot 2\cos x\,dx$$
$$=e^{-\sin x}\left( 2e^{\sin x}+C \right)$$
$$=Ce^{-\sin x}+2$$
This method avoided the issues I noted with your solution, so perhaps this is the easiest method for your problem after all.
A: here is another method. observe that $$y = 2$$ is a particular solution to the linear nonhomogeneous equation $$\frac{dy}{dx} + y \cos x=  2 \cos x$$ and too note that the homogeneous solution is $$y = Ce^{-\sin x}.$$  now use the principle of superposition to conclude that a general solution is $$y = 2+ Ce^{-\sin x}. $$
