Dr Herod Dive into C++ Series. building blocks -for & if #part 2

calculate without using the c/c++ math library or a calculator.



yangu imetoka hivi



why do you keep getting banned even after demanding fealties from so called commoners?

Why would anyone wanna do this in this day n age? Your time is better spent finding which libraries to work with rather than reinventing the wheel

What level are you at? Learner? Expert? And why only take care of one scenario?

I have never deeply used templates but why not also declare T power? Your calculations are nit wrong but confusing. So as said before, use libraries and reduce headaches

I’m not sure how scalable this is and 3^7/3^6^6 will break your little party.

am not a programmer professional know a couple of things or two
but made an assumption the exponent will always be an integer greater than zero. it’s always good to know how things works like ukienda pale stack overflow and ask how do you implement a simple MVC framework wengine will start pointing you to existing framework which was not the point of the question I get it they are well tested and documented libraries and codes but where’s the fun in that

what part is confusing


using namespace std;

T Spow( T base , int exponent){
if( exponent <= 0)
return 1;
return base * Spow(base,exponent -1);
int main()
cout << Spow(3,15) / Spow(3,12) <<endl;
return 0;

Beautiful code. Self explanatory.

I was about to give pointers to the non-recursive solution but this is more elegant

typing error-> 1/3^46649