Factorial Calculator

--Originally published at Loading…

This one was a little harder than the others, and it was a challenge to begin with because I couldn’t remember what is a factorial. But after I asked Ken and he explained me ( )…ie_factorial__6…the activity, it wasn’t too difficult. The activity consist in this:

Create a program that asks the user for a non-negative integer (let’s call that number n) and display for them the value of n! (n factorial).

After showing them the answer, ask them if they would like to try another number (with a simple y/n response) and either ask again (for y) or quit the program and wish them a nice day (if they answered n).

So, the first thing was do a function for the factorial, I established this function with the loop for, I wasn’t too sure of how doing it, so with the help of one page of Google and a classmate’s blog I could do it . In my main I established my variables as int and char, and then add the loop do/while for repeat until the user said no. Inside the “do” I put an if for the case that the number should be negative. This is my code:

factorial01factorial02

And this is how it works ?:

factorial03