EvenOdd

I have an error when I declare the array line 11. Can anyone help in this
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
  #include <iostream>
#include <cmath>
using namespace std;

int main ()
{

    // insert code here...
    int SIZE = 20;
    int num, i;
    int array[SIZE];
    for (i= 1; i<= SIZE; i++)
    {
        cin >> num;
        array[i]= num;
        

    }
    if (array[i] % 2 = 0)
    
    	cout << "This is the even numbers: " << array[i] << " " << endl;
    	
    else {
    	cout << "This is the Odd numbers: " << array[i] << " " << endl;
		}
	
    system ("pause");
    return 0;
}
Current C++ requires that the number of elements in an array must be a constant known at compile time.

1
2
3
4
5
6
7
8
9
10
11
12
int main ()
{
    //  int SIZE = 20; // *** not a constant

    const int SIZE = 20 ;
    // or: constexpr int SIZE = 20 ; // C++11

    // ...

    int array[SIZE];

    // ... 
Topic archived. No new replies allowed.