mathimatical problem

closed account (2wv7M4Gy)
what is the expression in c++ about a number in square for example 2*2 , how to write it 2 in the square ?
As in you want something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <float.h>
#include <math.h>
//Using "long double" as using the pow(v1, v2);

void ToThePowerOf(long double ldBase, long double ldPower)
{
	std::cout << "\n-----------Start Function----------" << std::endl;
	long double ldTemp = 0;
	const long double cBaseValue = ldBase;

	for(long double 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()
{
	long double 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:  ";
	long double 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.
That seems awfully long just to say
double pow(double,double);
http://www.cplusplus.com/reference/clibrary/cmath/pow.html
It's old, but point being is it's using pow and a function that's not in math.h
Topic archived. No new replies allowed.