Arrays

Write a program that declares an array named myArray with 8 components of the type
int. Initialize the array to 8 values that the user will input. Finally, pass the array as a
parameter to a new function called filterEvens. This new function will display all of the
even numbers in the array.

I'm confused and stuck on Arrays and 2D Arrays
what are ye confused about ??

arrays
 
int anArray[9];


2d arrays
 
int Array2D[9][9];


and what you need is normal 1D array
Last edited on
Yeah that's the thing, I don't know how to write what the instructions asks me to do.
To give you an idea...
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
#include <iostream>

//Function Prototypes.
void filterEvens(int[], int);

int main()
{
    const int s{ 8 };
    //declares an array named 
    //myArray with 8 components of the type int.
    int myArray[s]{0};

    // Initialize the array to 8 values that
    // the user will input.

    for (int x = 0; x < s; x++)
    {
	   std::cout << "Number " << x + 1 << " :";
	   std::cin >> myArray[x];
    }

    //Print Arrays.
    filterEvens(myArray, s);

    return 0;
}

// TO DO:
// This new function will display all of the
// even numbers in the array.
void filterEvens(int myArray[], int s)
{
    for (int x = 0; x < s; x++)
	   std::cout << myArray[x] << std::endl;
}

Very much appreciated thank you so much.
Topic archived. No new replies allowed.