I'm making a program that takes an input and chucks out the factorial result.
Now the program just chucks out what i put into it when i input 5 when I'm pretty sure it should output 120.
If anyone can point out where im going wrong it'd be appreciated.
sorry lowest one didnt see your reply but i already declared number before that and as far as i know i still have to put the ; there even if nothings going in it.
the number going in should be 5 then it gets reduced by 1 per iteration until it becomes less then 1 or equal to it which then stops the for loop
Or thats whats supposed to happen in my mind i could be wrong.
Use unsigned long long for maximum storage capacity, any larger than that and you'll have to look into either making your own way to handle larger numbers or finding libraries to do it for you. Long can map to the same type as int, which it sounds like it did in your case.
thank you that solved that little problem :P ive done factorial through recursion now aswell which didnt take aslong as i thought it would. having problem with it calling my functions through ive tried both switch and if statements. when i try to launch a function with the if statements it works fine but if i try to make it call them through an if or switch it just skips them completely.
oh damn forgot the ' '.
it has to hit one so the user can make a selection between either iterative or recursive and using if statements to allow for the option seemed like the easiest way as switch seemed excessive for only two options.
also cosmin i need a class as its part of the work that we need to make a separate class that has an iterative function and recursive which work out the factorial.