1
votes

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();
}
}
1
You have two main, with fibo() and void main() inside int main(). Why? - Marius Bancila
It was originally just the two fibo() and void main(), i added int main() to try and fix the problem, but nada. Does that affect it? - Jon Cain

1 Answers

0
votes

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