我收到错误但不知道如何修复它。我的代码如下:
#include <iostream>
using namespace std;
int main(){
int factorial = 1, current = 2, n;
cout << "enter number to calculate factorial of: ";
cin >> n;
while (current <= n){
factorial = current * factorial;
current++;
}
cout << n << "!= " factorial << endl;
while (n < 0) {
cout << "Must enter a positive number!\n";
cout << "re-Enter number to calculate factorial of: ";
cin >> n;
}
return 0;
}
答案 0 :(得分:2)
你错过了一个接线员:
cout << n << "!= " factorial << endl;
应该是:
cout << n << "!= " << factorial << endl;