Is it possible to run a ttest to compare mean score between groups by age?

Age is a categorical variable
There are two independent groups being compared
Mean score is continuous

If it is also possible to take into account gender that would be helpful but I can just create two separate variables for males and females and run the ttest twice. If this cannot be achieved using a ttest please can you advise if there is a test more appropriate?