displaying 2 numbers and check if they are even or odd in C++

Write your question here.
hi every one,i know i am new in this site but i have been very much attracted.anyway; i am a first year student taking BScIT;My question is
i would like to know how to display 2 numbers and check them if they are even or odd
Untested:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

void isEven(int x){
    bool even = (x % 2 == 0);
    return even;
}

int main(){
    int n1 = 20;
    
    if(isEven(n1) == true){
        std::cout << "Number " << n1 << " is even!" << std::endl;
    }else{
        std::cout << "Number " << n1 << " is uneven!" << std::endl;
    }
    
    //Same for every number

    return 0;
}


EDIT:
The operator modulus (%) gets the rest out of a division.
10 % 8 = 2
5 % 2 = 1
10 % 5 = 0
Last edited on
Topic archived. No new replies allowed.