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

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:

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;
    }           
 } 

}


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Increased array size. after increaseSize function some arguments of the same array are invalid. C lang

The program takes some txt input from "numbers.txt" file. It first counts the&nbsp;<strong><em>amount</em></strong>&nbsp;of all the numbers (freqCount)in that text file, than reads the file again and with the use of malloc it creates two arrays A and B , of which both have size equal to the&nbsp;<strong>amount</strong>&nbsp;of all the numbers in the text file. So far so good.

C/C++ vs. Rust: A developer’s perspective

In this post, you'll see the difference between Rust and C/C++ in a developer’s perspective