#include
using namespace std;
int main()
{
int i = 1, s = 1, n;
cout << "输入n="; cin >> n;
while (n<1 || n>15){ //n的值若不在1-15范围内将不断循环输入
cout << "n的范围是1-15,请重新输入n的值\n输入n=";
cin.clear();
cin.sync();
cin >> n;
}
do
{
s = s*i;
i++;
} while (i <= n);
cout << "n!=" << s << endl;
return 0;
}
这么改
cin>>n;
while(1)
{
if(n<1 || n>15)
{cout<<"n的值超出范围,请重新输入!"<
cin>>n;}
else
break;
}
if (n<0||n>15) cout<<"error:out of range";