How to return the number of values input into an array?

Basically, I'm doing a homework assignment but am stumped. Any help or guidance would be greatly appreciated. I got part one to work, however when I tried to return the # of user inputs in part two I got a 'Segmentation Fault'. Here are both steps:

P2.1 Write a program consisting of main and displayArray functions. The main function declares an integer array with 10 elements and at the same time initializes them with up to 10 arbitrary values. The main function then calls displayArray function to display the contents of the array.

P2.2 Expand P2.1 with an additional fillArray function that prompts the user to enter up to 10 (size of the array) integers. Since a statically allocated array is often partially filled with values less than the actual size or storage capacity of the array (10 in our case), so the fillArray function must return a positive integer value representing the actual # of input values entered by the user.

// Course: CS2400-01 Computer Science II // Name: Ortiz, Matthew // Assignment: P2.1 // Date assigned: 1/22/19 // Date due: 1/31/19 // Date handed in: 1/31/19 // Remark:

#include <iostream>
using namespace std;
int displayArray(int arr[]);
int fillArray(int newArray[], int &amp;inputs);

const int size = 10;

int main() {

int x, inputs = 0;
int arr[size] = {0,1,2,3,4,5};
int newArray[] = {};

displayArray(arr);

cout &lt;&lt; "Enter .5 when finished. ";
fillArray(newArray, inputs);

cout &lt;&lt; inputs;

cin &gt;&gt; x;
return 0;

}

int displayArray(int arr[]) {

for (int i = 0; i &lt; size; i++)
    cout &lt;&lt; arr[i] &lt;&lt; " " &lt;&lt; endl;

}

int fillArray(int newArray[], int &inputs) {

for(int i = 0; ; i++) {
cout &lt;&lt; "Enter an integer: " &lt;&lt; endl;
cin &gt;&gt; newArray[i];

if(newArray[i] == .5) {
inputs = i + 1;
return inputs;
break;
    }           
 } 

}


#c++ #arrays

5 Likes1.40 GEEK