Factorial Calculator

Hello everyone,

As you remember I was working on some WHILE LOOPS codes. Now is not the exception.

Instructions:

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).

And this is the code:

2016-02-09 (1)

 

We are using two WHILE LOOPS. Why?

  1. The first one is for the answer of the factorial. Here we are using a logical process so be careful and aplpy the data I showed to you in the last WSQ.
  2. The second WHILE LOOP is because we want to question the user if he/she want to type another number and when he/she type N the loop is going to end. (IT´S IMPORTANT TO DECLARE THE COUNTER AND ACUMULATOR INSIDE THE TOP OF THE FIRST LOOP BECAUSE IF YOU DIDN’T THE LOOP IS GOING TO SAVE THE LAST VARIABLES’S VALUES.

The rest is just COUT. It is not difficult so you just need to practice and you can be an expert in this topic. This time I didn’t consult any info because I knew how to made it I just think logically and resolve the code.

Here is my code.

See you in my next post!

Top image by: https://www.flickr.com/photos/franganillo/3676227162/in/photolist-6ARCfW-3KUEYX-r12qc4-8EQHGq-2m2qz-bjMTNU-qDYNjU-BTs6PY-hFghFE-9kMCpd-biaBRX-5479uK-CXS95v-7vBmWZ-9Pcixd-8uiEZh-biaCV6-cGfaG5-57R2QV-bnZLkt-62kgKT-shxyY9-ucnpR-4H1juM-6yvjme-jusv8v-tpkfA-bkJRub-9VwGaa-4nffv9-nhpFZA-u1sWi-qDd1aC-rrLy7G-9VCot1-5WKb9m-f3MmR6-8LFbhE-5Xcyed-gumt7v-2WdaSy-FP86B-9biQY6-9Ajs9g-bgfFKc-o95B4i-7ASToy-8nuB5W-6DtkQL-98yw4q

CC BY-SA 4.0 Factorial Calculator by sercho93 is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.