Optimum angle

Hi everyone, im hoping that someone may be able to advise me on an issue i currently have.
I am trying to implement a Physics computer simulation (only basic) designed for children learning about forces. One of the sub games that i have created is to fire a character from a cannon and find the optimum angle, which ends up at 45 degrees.
However, the second sub game models drag force on the projectile, taking into account its mass, area, drag coefficient, and the air density. The equations are solved using an RK4 method. Excuse my lack of knowledge on this subject, but I am not that hot on physics, i just have an interest which is why i decided to model this simulation as my final university project as a computing student. Now, the question i have is that ive always understood that 45 degrees is the optimum angle to travel the farthest, but when simulating the drag projectile, the optimum angle is now 35. Is this correct, in that 45 degrees would no longer be optimum, or am i going wrong somewhere?
Many thanks

the optimum angle changes because of the drag coefficient and it is continuous. Meaning that the optimum angle depends on the value of the coefficient, and is not 35 for all drag coefficients, just that particular value. It approaches 45 as the coefficient goes to zero. I believe you can solve for it by minimizing the amount of work done by drag.

An intuitive way to see this would be to realize that there is a force along the horizontal in the opposite direction to the velocity of the projectile. Add this force to the downward gravitational force and the resultant force acting on the projectile will be at a nonzero angle to the vertical. Hence, your angle of projection to maximize the range must be lower than 45 degrees. It would be similar (though not the same) as firing a projectile on an uphill slope. but you are now viewing the whole thing from a rotated point of view.

Ah, many thanks for your responses. Id suddenly became very worried when i realised that 45 was no longer optimum, and given my lack of knowledge id felt id made a mistake somewhere in the code. Again, your responses are much appreciated.