Exponent in Formulas?

How can I declare an exponent? Can you please help me? Thanks guys! :)

//Type the average surface temperature for "planet" in Celsius.
std::cout << "Type the average surface temperature for " << planet << " in Celsius: " << std::endl;
std::cin >> temperature;
E = (1) * (.000000056697) * (temperature)^4;
Use the pow() function or just manually multiply it out. ^ is for bitwise exclusive OR.
Hi,

A slightly different thing, apart from the exponent:

.000000056697 can be written 5.6697e-8

If that is a constant, you should declare it as such, then use the variable name:

1
2
3
4
const double TheConst = 5.6697e-8; // rename this variable to something meaningful - I don't know what it is, so I used this bad name instead

double TSquared = AvgSurfaceTemp* AvgSurfaceTemp  // might come up with a better name than TSquared 
double E = TheConst * TSquared  * TSquared ;


That way you can avoid using "magic numbers" in your code. If the value of a variable might change, you change it in one place, rather than everywhere throughout your code.



Not sure why you are multiplying by 1

With double or float, I always write a digit before and after the decimal point, as in 1.0 , 0.1 not 1 or .1

If you are using formulae from documentation (wiki say) then as comments, copy & paste the URL and the actual formula before the code.

Hope this helps a bit :+) And Good luck with your coding :+)

Edit:

C++11 has overloads for the pow function, so you could pass the exponent of 4 as an int

http://en.cppreference.com/w/cpp/numeric/math/pow


Edit2:

I mention this because I suspect the compiler is smart enough to multiply when using an integer exponent instead of using a binomial series expansion.
Last edited on
Okaaaay. Thanks man :)
Topic archived. No new replies allowed.