#WSQ09-Factorial calculator

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

This where my instructions. And this is how I what I did.

This program accepts a “n” positive number and multiplies it in a sequence for example: 5!=102, this is also 1 x 2 x 3 x 4 x 5=120.

Also this program has a loop that ends with the sequence of the multiplications.

//CODE:

#include <iostream>
using namespace std;

int main(int argc, char const *argv[]) {
int n, n2, conta;
char ans;
std::cout << “This program prints the factorial of <n> number.” << std::endl;
do {
std::cout << “Please enter a non-negative number to calculate the factorial.” << std::endl;
std::cin >> n;
if (n==0) {
std::cout << “The factorial is… 1” << std::endl; //cuando corro el programa sale factorial is… 1 y después factorial is… 0 y despues vulve a preguntar….
}
conta=n;
do {
conta=conta-1;
n=n*conta;
} while(conta !=1);
std::cout << “The factorial is… “<<n << std::endl;
std::cout << “Do you like to add another factorial? Write <y> for yes and <n< for no” << std::endl;
std::cin >> ans;

} while(ans==’y’);

return 0;
}

Captura de pantalla 2016-02-17 a las 18.58.58

CC BY-SA 4.0 #WSQ09-Factorial calculator by everolivares is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.