首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修复错误??错误:在"factorial“之前需要";”?它在第16行写着

如何修复错误??错误:在"factorial“之前需要";”?它在第16行写着
EN

Stack Overflow用户
提问于 2011-09-28 14:22:43
回答 1查看 185关注 0票数 0

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

代码语言:javascript
复制
#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;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-09-28 14:28:07

您缺少一个运算符:

代码语言:javascript
复制
cout << n << "!= " factorial << endl;

应该是:

代码语言:javascript
复制
cout << n << "!= " << factorial << endl;
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7579109

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档