Skip to content

Instantly share code, notes, and snippets.

@batmantec
Created February 5, 2016 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save batmantec/9807d28cc44bf5790465 to your computer and use it in GitHub Desktop.
Save batmantec/9807d28cc44bf5790465 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main(){
int n,count,product,sum,fac;
char answ;
cout<<"This program calculate the factorial of a number."<<endl;
do {
cout <<"Please type an positive number: ";
cin >> n;
count=1;
product=1;
sum=1;
if (n>1) {
do{
count++;
product=product*(sum+1);
sum++;
fac=product;
}while (count!=n);
cout <<"The factorial of "<<n<<" is: "<<fac<<endl;
cout <<"Would you like to type another number (y/n)?";
cin >> answ;
} else {
if (n==1) {
cout <<"The factorial of 1 is: 1"<<endl;
cout <<"Would you like to type another number (y/n)?"<<endl;
cin>>answ;
} else {
cout<<"The number that you enter was negative, please try again."<<endl;
answ='y';
}
}
} while(answ=='y');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment