-4

I would like to know how to declare and call this function from within the main:

void Part1()
{
int array1[10];
int n;
int i;
for (i=1; i<=10; i++) 
    {
    cout<<"Please enter an entry for position "<< i<<": "<<endl; 
    cin>>n;
    array1[i] = n;
    }
cout<<endl;
i = 0;
for (int i=0; i<10; i++) 
    {
    cout<<array1[i]<<endl; 

    }
return 0;
}

When I try to run my int main() I get nothing. I am aware that void does not return anything, but I thought simply calling the function (ie "Part1") would work. What am I doing wrong?

EDIT: This is how I have been calling it:

int main (){
Part1;

system("PAUSE");
return 0;
}
Ishmael
  • 235
  • 3
  • 8
  • 17

2 Answers2

3

To call a function, you need to use parentheses: Part1();. The parentheses contain the arguments that will be passed to the function, but in your case there are none so the parentheses are empty.

Also, the index of your first for loop is incorrect. Your array's indices start at 0 and end at 9. You seemed to get this correct in the second for loop but not in the first. It should be for (int i=0; i<10; i++).

Joseph Mansfield
  • 108,238
  • 20
  • 242
  • 324
3

In order to invoke a function, you must use the function-call operator, namely, ().

Like this:

int main (){
  Part1();

  system("PAUSE");
  return 0;
}
Robᵩ
  • 163,533
  • 20
  • 239
  • 308