Calculate beta in C++