.
You can solve the problem using the system of 2 equations in 2 unknowns
From the condition, you have this system of 2 equation in 2 unknowns
R + B = 40 (1) (counting red (R) and blue (B) shirts)
3R + 4B = 150 dollars (2) (counting dollars)
The most convenient way is to use Elimination method.
For it, multiply eq(1) by 3 (both sides) and then subtract the result from eq(2). You will get
4B - 3B = 150 - 3*40,
B = 150 - 120 = 30.
Answer. 30 blue shirts and the rest (40-30) = 10 red shirts.
Solved. // On the way you learned on how the Elimination method works.
Or you can solve it using one single equation.
Let B be the number of blue shirts.
Then the number of red shirts is (40-B).
The money equation for the total is
3*(40-B) + 4B = 150,
120 - 3B + 4B = 150,
B = 150 - 120 = 30,
and you get the same answer as in previous solution.