2015-10-18 81 views
1

这是我的代码,它的C++语言,我有我所有的程序中的int main(){},我仍然收到此错误消息。帮帮我?LNK1561 t入口点必须定义

#include<iostream> 
#include <ctime> 
using namespace std; 

int main(){ 

int fibo(int n) 
{ 
    if (n == 0) 
     return 0; 
    else if (n == 1) 
     return 1; 
    else 
     return fibo(n - 1) + fibo(n - 2); 
} 

void main() 
{ 
    clock_t t; 
    t = clock(); 
    int n, i; 
    cout << "Enter the total number of elements: "; 
    cin >> n; 
    cout << "\nThe Fibonacci series is:\n"; 
    for (i = 0; i < n; i++) 
    { 
     cout << fibo(i) << " "; 
    } 
    t = clock() - t; 
    cout << "\nThe time required is:"; 
    cout << t/CLOCKS_PER_SEC; 
    getch(); 
} 
} 
+4

你有两个主要的,在'main main()'里面用'fibo()'和'void main()'。为什么? –

+0

它最初只是两个fibo()和void main(),我添加了int main()来尝试修复问题,但是nada。这会影响它吗? –

回答

0

删除多余的主要

#include <iostream> 
#include <conio.h> 
#include <time.h> 

// force to use main entry point as startup 
#pragma comment(linker, "/ENTRY:mainCRTStartup") 

using namespace std; 

int fibo(int n) 
{ 
    if (n == 0) 
     return 0; 
    else if (n == 1) 
     return 1; 
    else 
     return fibo(n - 1) + fibo(n - 2); 
} 

int main() 
{ 
    clock_t t; 
    t = clock(); 
    int n, i; 
    cout << "Enter the total number of elements: "; 
    cin >> n; 
    cout << "\nThe Fibonacci series is:\n"; 
    for (i = 0; i < n; i++) 
    { 
     cout << fibo(i) << " "; 
    } 
    t = clock() - t; 
    cout << "\nThe time required is:"; 
    cout << t/CLOCKS_PER_SEC; 
    getch(); 
    return 0; 
} 

或转到项目比配置属性的属性 - >链接器 - >命令行并粘贴到其他选项/子系统:CONSOLE

+0

应该是'int main'而不是'void main'。 – emlai

+0

既可以是int也可以是无效的 – Mykola

+1

Uhm nope:http://stackoverflow.com/q/204476/3425536(好吧,从技术上讲它可能很有用,但这并不是标准定义的,你不应该依赖它。 “'void main()'被C++标准明确禁止,不应该使用”) – emlai

相关问题