Concept:
The given differential equation is a first-order separable differential equation. In such equations, all terms containing \(y\) are brought to one side and all terms containing \(x\) are brought to the other side.
After separating variables, both sides are integrated independently.
Step 1: Rewriting the differential equation in separable form.
Given:
\[
\left(\frac{2+\sin x}{1+y}\right)\frac{dy}{dx}=-\cos x
\]
Multiply both sides by
\[
\frac{1+y}{2+\sin x}
\]
We get:
\[
\frac{dy}{dx}
=
-\frac{(1+y)\cos x}{2+\sin x}
\]
Now divide both sides by \(1+y\):
\[
\frac{1}{1+y}\frac{dy}{dx}
=
-\frac{\cos x}{2+\sin x}
\]
Multiplying throughout by \(dx\):
\[
\frac{1}{1+y}\,dy
=
-\frac{\cos x}{2+\sin x}\,dx
\]
Thus, the variables are completely separated.
Step 2: Integrating both sides.
Integrating:
\[
\int \frac{1}{1+y}\,dy
=
-\int \frac{\cos x}{2+\sin x}\,dx
\]
The left-hand side becomes:
\[
\ln|1+y|
\]
For the RHS, let:
\[
u=2+\sin x
\]
Then:
\[
du=\cos x\,dx
\]
Therefore:
\[
-\int \frac{\cos x}{2+\sin x}\,dx
=
-\int \frac{du}{u}
\]
Using the standard logarithmic integral:
\[
\int \frac{du}{u}=\ln|u|
\]
Hence:
\[
-\int \frac{du}{u}
=
-\ln|u|
\]
Substituting back:
\[
-\ln|2+\sin x|
\]
Therefore,
\[
\ln|1+y|
=
-\ln|2+\sin x|+C
\]
Step 3: Simplifying the logarithmic expression.
Using the logarithmic identity:
\[
\ln a+\ln b=\ln(ab)
\]
we obtain:
\[
\ln|1+y|+\ln|2+\sin x|=C
\]
\[
\ln|(1+y)(2+\sin x)|=C
\]
Removing logarithm:
\[
(1+y)(2+\sin x)=K
\]
where \(K\) is a constant.
Step 4: Using the initial condition \(y(0)=2\).
Substitute:
\[
x=0,\qquad y=2
\]
into the general solution:
\[
(1+2)(2+\sin0)=K
\]
Since:
\[
\sin0=0,
\]
we get:
\[
3\times2=K
\]
\[
K=6
\]
Thus, the required particular solution becomes:
\[
(1+y)(2+\sin x)=6
\]
Step 5: Finding \(y\left(\frac{\pi}{2}\right)\).
Substitute:
\[
x=\frac{\pi}{2}
\]
Since:
\[
\sin\frac{\pi}{2}=1,
\]
we get:
\[
(1+y)(2+1)=6
\]
\[
3(1+y)=6
\]
\[
1+y=2
\]
\[
y=1
\]
Hence,
\[
\boxed{
y\left(\frac{\pi}{2}\right)=1
}
\]