How to add a number to the end of partial array

For input two, how would I add the number the user inputed to the array.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  #include <iostream>
#include<cstdlib>
#include<ctime>
double getAverage(int[],int);
using namespace std;
int main()
{
    const int LENGTH =100;
    int array[LENGTH];
    srand(((unsigned)time(0)));
    
    
    int cnt = 0;
    cout << "Enter the length of the array: " ;
    cin >> cnt ;
    if( cnt > LENGTH )
        cnt = LENGTH ;
    
    for( int i = 0; i < cnt ; ++i )
        array[i] = 1 + rand() % 100;
    
    for( int i = 0; i < cnt ; ++i )
        cout << array[i] << ' ' ;
    cout << '\n' ;
    
    int input;
    cout << "Enter your menu choice" << endl;
    cout << "1. Find high, low, sum average" << endl;
    cout << "2. Add a number to the end" << endl;
    cout << "3. Find the index of a number" << endl;
    cout << "4. Insert number at index" << endl;
    cout << "5. Remove number" << endl;
    cout << "6. Remove number at index" << endl;
    cout << "7. Quit" << endl;
    cin >> input;
    
    if (input == 1) {
        
        int sum = 0;
        int average = 0;
        int high = array[0];
        int low = array[0];
        
        for (int dx = 0; dx < cnt; dx++)
        {
            sum += array[dx];
            if(array[dx] > high) high = array[dx];
            if(array[dx] < low)  low = array[dx];
        }
        average = sum/ cnt;
        cout << "The highest number is " <<high<<endl << "The lowest number is " << low<< endl<< "The average is " << average << endl;
    }
    else if (input == 2)
    {
        int number;
        cout << "Add a number" << endl;
        cin >> number;
  
    }
    
    return 0;
}
What do you mean by 'partial array'?

You add a number to an array like so:
1
2
3
4
5
6
7
if(cnt < LENGTH)
{
  array[cnt] = number;
  ++cnt;
}
else
 cout << "array is full" << endl;
Topic archived. No new replies allowed.