1. Factorial program problem

Hi I am a beginner and I wrote this program and everything works except when I input a letter instead of a number the program crashes any suggestions on how I can fix that and also any feedback on my program would be really appreciated.

Code:
```//Programmer: Fernando B
//Program: Factorial
//Purpose: factor a number      //need a boolean statement if the input is a letter??
//Formula 0! = 1
//        n! = n * (n-1)!
// Date: 12/21/10

#include <iostream>
#include <string>
#include <cmath>

using namespace std;

long long factorial (long long n)
{
if (n == 0) return 1;
return n * factorial (n-1);
}

int main ()

{

bool quit = false;
while ( !quit)

{
long long n;
cout << "Enter a positive integer to compute the factorial of: ";
cin >> n;

if (n <= 0)

{
cout << "Try again, please enter a positive integer!!!\a" << endl;

}

else if ( n >= 1)

{
char inputCharacter = 0;
cout << n << "! =" << factorial(n) << endl;
cout << "Would you like to try a new number? (Y)es (N)o" << endl;
cin >> inputCharacter;

if ( inputCharacter == 'Y' || inputCharacter == 'y')
{
quit = false;
}

else if ( inputCharacter == 'N' || inputCharacter == 'n')
{
cout << "Quitting...";
quit = true;
}

}

}

return 0;
system ("pause");

}```

2. cin >> is formatted input. If the input doesn't match the format, then >> is the wrong thing to do. Look at the FAQ which exactly matches your question "Why does my program enter an infinite loop if the user inputs invalid data? (C++) "

3. cin >> is formatted input. If the input doesn't match the format, then >> is the wrong thing to do. Look at the FAQ which exactly matches your question "Why does my program enter an infinite loop if the user inputs invalid data? (C++) "
Thanks a lot tabstop I will be spending some time at the FAQ from now on, so here is my finished program...
Code:
```//Programmer: Fernando B
//Program: Factorial
//Purpose: factor a number      //need a boolean statement if the input is a letter??
//Formula 0! = 1
//        n! = n * (n-1)!
// Date: 12/21/10

#include <iostream>
#include <ios>
#include <cmath>
#include <limits>

using namespace std;

long long factorial (long long n)
{
if (n == 0) return 1;
return n * factorial (n-1);
}

int main ()

{

bool quit = false;
while (!quit)

{

long long n;
cout << "Enter a positive integer to compute the factorial of: ";
while (!( cin >> n )){
cin.clear(); // clear error state
cin.ignore(numeric_limits <streamsize>::max(), '\n'); // remove the unrecognized char
cout << "Invalid data input. Please try again: \a";
}

if (n <= 0)

{
cout << "Try again, enter a positive integer! \a" << endl;
}

else if ( n >= 1)

{
char inputCharacter = 0;
cout << n << "! =" << factorial(n) << endl;
cout << "Would you like to try a new number? (Y)es (N)o" << endl;
cin >> inputCharacter;

if ( inputCharacter == 'Y' || inputCharacter == 'y')
{
quit = false;
}

else if ( inputCharacter == 'N' || inputCharacter == 'n')
{
cout << "Quitting...";
quit = true;
}

}
}

return 0;
system ("pause");

}```

4. So as it turns out I still had one more bug in the program when I asked to enter Y or N, the user could input any character and still go on... so here is the fix for that
Code:
```/*Programmer: Fernando B
Program: Factorial
Purpose: factor a number
Formula 0! = 1
n! = n * (n-1)!
Date: 12/21/10
notes with long long I can only go as far as 65*/

#include <iostream>
#include <ios>
#include <cmath>
#include <limits>

using namespace std;

long long factorial (long long  n)
{
if (n == 0) return 1;
return n * factorial (n-1);
}

int main ()

{

bool quit = false;
while (!quit)

{

long long  n;
cout << "Enter a positive integer to compute the factorial of: ";
while (!( cin >> n )){
cin.clear(); // clear error state
cin.ignore(numeric_limits <streamsize>::max(), '\n'); // remove the unrecognized char
cout << "Invalid data input. Please try again: \a";
}

if (n <= 0)

{
cout << "Try again, enter a positive integer! \a" << endl;
}

else if ( n >= 1)

{
cout << n << "! =" << factorial(n) << endl;

}

{
bool quit1 = false;
while(!quit1)

{

char inputCharacter = 0;
cout << "Would you like to try a new number? (Y)es (N)o" << endl;
cin >> inputCharacter;

if (!( inputCharacter == 'Y' || inputCharacter == 'y' || inputCharacter == 'N' || inputCharacter == 'n'))
{
cout << "Enter Y or N, try again! \a" << endl;
quit1 = false;
}

else if ( inputCharacter == 'Y' || inputCharacter == 'y')
{
quit1 = true;

}

else if ( inputCharacter == 'N' || inputCharacter == 'n')
{
cout << "Quitting...";
quit1 = true;
quit = true;

}

}
}

}

return 0;
system ("pause");

}```