#include <iostream>
#include <float.h>
#include <math.h>
//Using "long double" as using the pow(v1, v2);
void ToThePowerOf(longdouble ldBase, longdouble ldPower)
{
std::cout << "\n-----------Start Function----------" << std::endl;
longdouble ldTemp = 0;
constlongdouble cBaseValue = ldBase;
for(longdouble i = 1; i < ldPower; i++)
{
ldTemp = 0; //Reset Temp Value
ldTemp = ldBase * cBaseValue; //Calculate temp
ldBase = ldTemp; //Give Base temps value
std::cout << i << " Loop In Power Of = " << ldBase << std::endl;
}
std::cout << "\nFinal Answer : " << ldBase << std::endl;
std::cout << "------------End Function-----------" << std::endl;
}
int main()
{
longdouble valueOne = 0, valueTwo = 0;
std::cout << "Please enter a base value: ";
std::cin >> valueOne;
while((valueOne <= 1) || (_isnan(valueOne))) //(System::Double::IsNaN(valueOne))
{
valueOne = 0;
std::cout << "Please enter a number greater than 1: ";
std::cin >> valueOne;
}
std::cout << "Please enter a value for it to be powerd to: ";
std::cin >> valueTwo;
std::cout << "The Value of " << valueOne << " to the power of " << valueTwo << " is " << std::endl;
ToThePowerOf(valueOne, valueTwo);
std::cout << std::endl;
//Using The Math Method pow(value,value)
std::cout << "Using The POW Maths.h Method the answer is: ";
longdouble answer;
//Calling the method from the maths.h
answer = pow(valueOne, valueTwo);
std::cout << answer << std::endl;
}
Don't so much worry about the while loop in the main - was something I wrote a long time ago that I didn't finish. I just realized that was still in there.