-
help with arrays
this is the code i was given and told to make work but i cant figure it out at all,
void fill(int array[], int size);
// This function fills the given array with random integers in the range 0 to 100
(inclusive).
// size is the number of elements in array.
void print(int array[], int size);
// This function outputs the given array with one element per line. Each line of output
must contain two // values, the array index and the corresponding element. Here is an
example:
// Index Element
// 0 62
// 1 95
// 2 87
// : :
void findLargest(int array[], int size, int &max, int &maxIndex);
// This function receives an array and its size. Then, it finds the largest element and
returns it in variable
// max. The function also returns the index of the largest element through maxIndex.
void findSmallest(int array[], int size, int &min, int &minIndex);
// This function receives an array and its size. Then, it finds the smallest element and returns it through // min. The function also returns the index of the smallest element
through minIndex.
int search(int array[], int size, int key);
// This is a value-returning function. It receives an array, its size, and a key to search for. The function
// tries to find the key in the array. If the key is found, its corresponding index is returned; if the key is
// not found, -1 will be returned.
double average(int array[], int size);
// This is a value-returning function, it receives an array and its size. The function
returns the average of
// all array elements. The average will be a floating-point number.
void reverse(int array[], int size); // This function reverses all elements of the given
array. For example, if array = [10, 20, 30, 40], the // function converts it to [40, 30, 20, 10].
void statistics(int array[], int size, int &below51, int &above50);
// This function receives an array and its size. The function counts the number of elements that are
// below 51 (0 through 50) and also the number of elements that are above 50 (51 through 100).
//The function will return these counters through variables below51 and above50.
To test your functions use the following main program.
int main()
{
const int SIZE = 20;
int array[SIZE];
double avg; // Average of array elements
int max, maxIndex; // Largest element
int min, minIndex; // Smallest element
int key, keyIndex; // Search item
int below51, above50; // Counters for statistics
fill(array, SIZE);
print(array, SIZE);
findLargest(array, SIZE, max, maxIndex);
cout << “Largest = “ << max << “ at index “ << maxIndex << endl;
findSmallest(array, SIZE, min, minIndex);
cout << “Smallest = “ << min << “ at index “ << minIndex << endl;
avg = average(array, SIZE);
cout << “Average = “ << avg << endl;
statistics(array, SIZE, below51, above50);
cout << “Number of elements between 0 and 50 = “ << below51 << endl;
cout << “Number of elements between 51 and 100 = “ << above50 << endl;
reverse(array, SIZE);
cout << “Array after reversing: “ << endl;
print(array, SIZE);
// Let’s search my array
cout << “Enter an element to search for: “;
cin >> key;
keyIndex = search(array, SIZE, key);
if (keyIndex > -1)
cout << “Found your search element at index “ << keyIndex << endl;
else
cout << “Search element was NOT FOUND! “ << endl;
return 0;
}
i know its a lil overwhelming
-
Lemme guess, you got a popup asking you to add code tags.
So your workaround solution was to rip out all the braces from your code and the error went away.
FAIL!
Now post your ACTUAL code unmodified, and figure out how to use the code tags.