C++ Odd or Even

This is a great code example for determining if user input is a Odd or Even Number


* Featured Code Example Created and submitted by tooselfish via Sololearn.


C++ Odd or Even


#include <iostream>

int main() {

    int a = 0;
    
           // input one whole integer
    std::cin >> a;
    
           // for input failure
    if( std::cin.fail() ){
        std::cerr << "Wrong input!\n";
        return 1;
    }
    
    std::cout << "Your number is: " << a << std::endl;
    
         // test odd or not
    if (a %2 != 0){
        std::cout << "Your number is odd!" << std::endl;
    } else {
        std::cout << "Your number is even!" << std::endl;
    }
    
    return 0;
}

Click here to run this code



More Free Code Examples:


Java Odd or Even





Comments

Popular posts from this blog

Multi-tap Keypad Text Entry

Crypto Mining