Objective function is to maximize profit. Decision variables is how much qty of $C$ and $D$ to produce?
Raw material can produce either $A$ or $B$.
Product $C$ requires an input of qty $A$ and $\frac{1}{2}B$. Product $D$ requires an input of qty $2A$ and $B$. Cost to produce $A$ is $2$ and $B$ is $4$.
In the constraint, if I put $A + \frac{1}{2}B=C$, the program will set $B$ to 0 as its cost is higher.
How to write the constraint so that $C$ must consist exactly the qty ratio of $A$ and $\frac{1}{2}B$?
If you write $A+\frac{B}{2} = C$, it means that to produce $1$ unit of $C$ you can either use $1$ unit of $A$ or half a unit of $B$.
What you want is $1$ unit of $A$ AND half a unit of $B$, so you need to write the constraint the other way around : \begin{align} C &= A \\ C &= 2B \end{align}