One thing to look out for is integer division. the return type of fact, x and n are all integers. Try this:
#include<iostream>
using namespace std;
int fact (int no)
{
int total;
for (int i=0; i<=no; i++)
{
if(i ==0)
total = 1;
else
total = total * i;
}
return total;
}
int main()
{
int x,n;
double result;
cout<<"Please key i x value : ";
cin>>x;
cout<<"\n";
cout<<"Please key in n value : ";
cin>>n;
if (x<n)
cout<<"Wrong input, x valur must be greater than n !!\n"<<endl;
else
cout <<"\nResult = 1 +2!/"<<x-2
<<" - 3!/"<<x-3
<<" + 4!/"<<x-4<< " - "<<n
<<"!/"<<x-n
<<" = "<<1+(fact(2)/static_cast<double>(x-2))-(fact(3)/static_cast<double>(x-3))+(fact(4)/static_cast<double>(x-4))-(fact(n)/(static_cast<double>(x-n)));
return 0;
}