This program I wrote is supposed to print some numbers:
#include <iostream>
using namespace std;
int main()
{
int hitung(int A[], int n)
{
int jumlah = 0;
for (int i = 0; i < n; i++)
{
jumlah = jumlah + A[i];
if (i % 2 == 1)
{
cout << A[i];
}
}
return jumlah;
}
}
However, when I try to compile it I get these error messages:
main.cpp: In function 'int main()':
main.cpp:6:5: error: a function-definition is not allowed here before '{' token
{
^
main.cpp:18:1: error: expected '}' at end of input
}
^
While the first error is understandable since function definition can't be in other function, I don't understand the 2nd error since all my brackets are closed.
Why is the compiler producing the second error?