My array menu needs help!!!

My assignment is to Write a program that displays the following menu:(I have done 0 and I'm working on 1) I need help how to work #1.
0. Create array
1. Find high, low, sum average
2. Add a number to the end
3. Find the index of a number
4. Insert number at index
5. Remove number
6. Remove number at index
7. Quit

Create an array of integers with size 100. Use a variable to store the number of filled elements (not all 100 elements will hold user data).
0. Create array: Asks user how many numbers to fill (the length of the partially filled array), with
random numbers 0-99. First fill all 100 elements with zeroes then insert as many random
numbers as specified by the user. Validate the user entered number (1-99).
1. Calculates and prints the highest value, lowest, sum, and average of the partially filled array.
2. Add a number to the end: asks user to enter a number and adds it to the end of the partially
filled array.

This is what I have so far.

<#include <iostream>
#include<cstdlib>
#include<ctime>
double getAverage(int[],int);
using namespace std;
int main()
{
int input;
cout << "Enter your menu choice" << endl;
cout << "0. Create Array" << 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;
const int LENGTH =100;
int array[LENGTH];
srand(((unsigned)time(0)));
if(input==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' ;}
if (input ==1){
int sum = 0;
int average = 0;
int high = array[0];
int low = array[0];
int cnt=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 << high << low << average << endl;
}

return 0;
}>
Last edited on
You're asking a lot of questions trying to find sum/average.

For the record, to use the code tags you have to click the <> button at the right, which will add the code tags: [code ] [ /code]
You need to put your code between those tags not between < >.
Last edited on
is it correct now?
Topic archived. No new replies allowed.