I worked for about 2 days on this before everything was ironed out. I included comments for how to use it and how it works internally. There are a few lines specifically that I am really proud of, like where I detect if there is no solution AND prevent negative values from being passed into a sqrt() function in one stroke. The math may look a bit weird (using b*b instead of b^2), but anything that appears out of place is deliberate. The core maths to making this work only needs 2 lines, but the rest here makes it more powerful and maybe a tiny bit faster. Without farther ado, here is the function.
Currently running Recuva because I did this in C++ and somehow lost the source… Also, for 8th grade, not bad at all. I would suggest that you look into OOP though, can be very useful, if you use it right.
Oops! I was using pcsr in the calculation before I realized that it was not necessary. I will move it over in my VS project. Thanks for pointing that out!