error C2601: ‘main’ : local function definitions are illegall – MS VS 2013 Compiler

Your bracketing is broken. The net result is that you are attempting to define your main function inside ciong. And C++ does not support nested function definitions. Hence the compiler error.

The code should be:

#include "stdafx.h"
#include <iostream>
using namespace std;


int ciong(int n)
{
switch (n)
{
case 1:
    return 1;
    break;
case 2:
    return 2;
    break;
default:
    int pomocniczaLiczba = ciong(n - 2) + ciong(n - 1) * ciong(n - 1);
    return pomocniczaLiczba;
    break;
}
} // <----- Oops, this was missing in your code

int main()
{
int n;
cin >> n;
cout << ciong(n) << endl;
return 0;
}

And there are other bugs. For example, you meant cout << ciong(n).

Leave a Comment