I seem to have trouble for either finding a descriptive piece of code, or finding a description of how to simplify radicals. I plan to use this as a separate function in my expanded quadratic equation program. The function I use is just perfect the way it is, except for when I get to a number dealing with 15, since 15 is not prime nor is it made of any perfect squares.
Here is the function:
double getPerfSquareDivisor(double squareRoot)
{
double divisor = 1;
double exponent;
double num = 0;
char prime = ' ';
if (squareRoot < 0)
{
squareRoot *= -1;
}
cout << "squareRoot: " << squareRoot << endl;
prime = getIsPrime(squareRoot);
cout << "prime(getPerfSquareDivisor): " << prime << endl;
if (prime == 'N')
{
for (double exponBase = 1; exponBase * exponBase <= squareRoot && prime == 'N'; exponBase += 1)
{
exponent = pow(exponBase, 2);
cout << "Exponent is: " << exponent << endl;
num = squareRoot / exponent;
cout << "Num is: " << num << endl;
outsideRad = exponent;
prime = getIsPrime(num);
cout << "primein for loop(getIsPrime): " << prime << endl;
}
divisor = num;
cout << "Divisor: " << divisor << endl;
}
else
{
cout << "squareRoot: " << squareRoot << endl;
divisor = squareRoot;
cout << "Divisor(Prime): " << divisor << endl;
}
//End if
return divisor;
}
Most of the couts are not going to be in the final product, I am just currently using them to somewhat debug, which has not really been working out. I know this is not the correct way to do this, but I'm just showing that I have at least tried to figure it out on my own. I am also aware that most ways of calculating this correctly use the modulus operator, which I tend not to use because of my favoritism of the double data type, and my limited knowledge of it.
Thanks! Your input is appreciated!