how to use pow (x,y)?

this is one of my formula in my code

wavelength = (Electronic_Transitions * Electronic_Transitions)/(1.10 * pow (10,7)) * ((Electronic_Transitions * Electronic_Transitions) - 1)),

the pow problem shown by Microsoft Visual Studio 2010 is (Error: more than one instance of overloaded function 'pow" matches the argument list:)
pow (double, double);

try
pow(10.0, 7.0)

wavelength = (Electronic_Transitions * Electronic_Transitions)/(1.10 * pow (10.0,7.0)) * ((Electronic_Transitions * Electronic_Transitions) - 1)),
yes it works, thanks a lot.

I have 1 more question can i have a nice output such as wavelength = 1.022727 x 10 ^ -7 instead of wavelength = 6.5454545e-006 and I do not understand what does the "e" mean
e is not the natural logarithm, just in case that is what you are thinking.

e is short for "x10 ^" so 4.5e-3 means 4.5x10^-3. Any scientist, programmer or engineer will understand what you are talking about if you just put "e" so don't worry about that. Therefore I would consider your output to already be nice.

If you want to structure it in another way, I suppose you could do the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <iomanip>

double get_exp(double num)
{
  return log(num) / log(10.);
}
double get_sci(double num)
{
  return num/pow(10,get_exp(num));
}

void output_number(double num)
{
  cout << setprecision(6) << get_sci(num) << "x 10 ^" << (int)get_exp(num);
}


Now just use output_number whenever you want to display a number in cout. You could also play with these so that the output always has an exponent as a multiple of 3 (engineering notation) which can be useful too.
Last edited on
lol, now only I realize my answer is wrong.

in this formula,
wavelength = (Electronic_Transitions * Electronic_Transitions)/(1.10 * pow (10,7)) * ((Electronic_Transitions * Electronic_Transitions) - 1)),

when Electron_Transitions = 3, my answer should be 1.022727e-007 but my output is 6.5454545e-006, anything wrong with my formula?
yes I have encountered the problem myself.

Special thanks to stebond and maniax for helping me sincerely
If you are getting the wrong output, it isn't the C++, it's the equation.

This is the readable version of your equation. Compare this against what you meant to write.
lambda = (ET^2) * (ET^2 - 1) / (1.1 x 10^7)
Topic archived. No new replies allowed.