Let's not forget bad teachers. My kids always had A's until they had this particular calculus teacher. My kids got lost fast. We hired a tutor and they got back on the path fast. The tutor told us that she made a pile of money off kids that were assigned that particular teacher.
That was up to calc, not including. I get the bad teacher part. I had one in high school for two straight years. I basically had to teach myself and work with classmates in study groups. That teacher had no business being a teacher.
Sometimes it is just bad luck...I went to school in a VERY rural part of South Louisiana. The local school was totally oriented to kids that were going to stay local and farm. Highest math was a bit of descriptive geometry. The math teacher was good, the curriculum just wasn't suited to a guy like me.
Despite the above background, I went to LSU and got a PhD in chemistry. Making up the math deficit was probably the hardest part of my "college journey", and took a LOT of extra work and study that kids who went to college prep schools had already done (maths through first calculus).