1

Here is my code, its in C++ language and I have int main(){} as I do in all of my programs and I'm still getting this error message. Help?

#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();
}
}
MattAllegro
  • 4,414
  • 5
  • 33
  • 42
Jon Cain
  • 37
  • 3

1 Answers1

0

remove an extra main

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

or go to project properties than Configuration Properties -> Linker -> Command Line and paste to Additional options /SUBSYSTEM:CONSOLE

Mykola
  • 3,152
  • 6
  • 20
  • 39
  • Should be `int main` not `void main`. – emlai Oct 18 '15 at 18:47
  • 1
    Uhm nope: http://stackoverflow.com/q/204476/3425536 (well, technically it _may_ work but that's not defined by the standard and you shouldn't rely on it. From the answer: "`void main()` is explicitly prohibited by the C++ standard and shouldn't be used") – emlai Oct 18 '15 at 18:49
  • I tried your solution of having into fibo as well as int main(), and still no entry point error.? – Jon Cain Oct 18 '15 at 22:49
  • I run it on MS Visual C++ – Mykola Oct 18 '15 at 22:56