我该如何修复错误?错误:预期“;”在“阶乘”之前?它在第16行说

时间:2011-09-28 06:22:43

标签: c++

我收到错误但不知道如何修复它。我的代码如下:

#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;
}

1 个答案:

答案 0 :(得分:2)

你错过了一个接线员:

cout << n << "!= " factorial << endl;

应该是:

cout << n << "!= " << factorial << endl;