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

}


c++ arrays

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

C++ Arrays And Multidimensional Arrays

In this article we are going to talk about C++ Arrays And Multidimensional Arrays, so c++ arrays are collection of the elements that are the same type.

C++ Arrays And Multidimensional Arrays

In this video we are going to talk about C++ Arrays And Multidimensional Arrays, so c++ arrays are collection of the elements that are the same type.

Anonymous array in C#| Anonymous Collection | C# Bangla Tutorial | Advanced C#

LIKE | COMMENT | SHARE | SUBSCRIBE In this tutorial, I will discussed about Anonymous Array in C#. Blog : http://aspdotnetexplorer.blogspot.com Like our page...

Count of triplets (a, b, c) in the Array such that a divides b and b divides c

A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

Loops in C++ | For, While, and Do While Loops in C++

In this Video We are going to see how to use Loops in C++. We will see How to use For, While, and Do While Loops in C++.