简体   繁体   English

错误:重新定义“int main()”,即使“int main()”只出现一次

[英]error: redefinition of 'int main()' even if "int main()" apperas only once

I was working on a problem on Pbinfo: https://www.pbinfo.ro/probleme/898/sumfactcif but each time I tried to run my code it said:我正在处理 Pbinfo 上的一个问题: https://www.pbinfo.ro/probleme/898/sumfactcif但每次我尝试运行我的代码时它都说:

sumfactcif.cpp: In function 'int main()':
sumfactcif.cpp:35:5: error: redefinition of 'int main()'
 int main(){

     ^
sumfactcif.cpp:25:5: error: 'int main()' previously defined here
 int main()

     ^

I don't know what to do because in my IDE(Codebloks) the code has no errors.我不知道该怎么做,因为在我的 IDE(Codebloks) 中代码没有错误。 Here's the code if you can help me:如果你能帮助我,这是代码:

#include <iostream>

using namespace std;

int sumfactcif(int x)
{
   int p,p1=0;
   while(x>0)
   {
       int u=x%10;
       p=1;
       for(int i=1;i<=u;i++)
       {
           p=p*i;
       }
       p1=p1+p;
       x=x/10;
   }
   return p1;
}

int main()
{
    int x,fct;
    cin>>x;
    fct=sumfactcif(x);
    cout<<fct;
}

Thanks!谢谢!

Answer: Looks like the site already added an "int main" to my code, so that the result had two "int mains".答案:看起来网站已经在我的代码中添加了一个“int main”,所以结果有两个“int mains”。 Thanks to @churill for pointing that out感谢@churill 指出这一点

Upload this :

int sumfactcif(int x)
{
   int p,p1=0;
   while(x>0)
   {
       int u=x%10;
       p=1;
       for(int i=1;i<=u;i++)
       {
           p=p*i;
       }
       p1=p1+p;
       x=x/10;
   }
   return p1;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM