bigNumbers fakulty

Hello everybody,

I have a problem with my Code, I implemented a new Data Typ bigNumbers and trying to calculate faculty with it. Now everything works fine, except that when i want to Calcutlate the faculty of x, but it calculates me the faculty of x-1. And i have no idea why, my solution was to call the Method with x + 1. Might someone tell me why?
Here the code: http://pastebin.com/AryiKUXP

Thanks Mrniceguy420
Last edited on
> num * faku(num.dec());
`.dec()' modifies the object. I'll say undefined behaviour (the arguments may be evaluated in any order)
well perfect, it works now. Good tip :) Thanks.
Hey, another question, I changed my code so it works. But im not comfortable with the Solution. How can i solve the faculty without an temporary variable. In other words how do i need to redesign my Subtraktion method so i can perform it in the Same line?

Fixed code http://pastebin.com/AryiKUXP

if my question is unclear feel free to ask and sorry for my bad english :)

Mrniceguy420
I don't quite see why you need a temporary variable. What's wrong with just using num?

-Albatross
> bigNumbers& operator - (const int& num);
That method should be const. It is counter intuitive that the left arguments gets modified.

> How can i solve the faculty without an temporary variable.
Iterate instead of recurse.
Then you need one variable for the accumulate and another one for the next factor; instead of `n' factors.

Also, bigNumbers faku(bigNumbers num) the parameter may be simply int
i know it would have been easier with an integer parameter, but then i decided to try it though bigNumbers for some learning effects. The sense behind it might be questionable :)
Last edited on
Topic archived. No new replies allowed.