Finding Multiples of 2 – C++

What it does:

A c++ program which prompts the user to enter a number it then checks using an if statement if it is a multiple of 2. If the number entered is a multiple of 2 it will the print out that the number they enter was a multiple, if it is not the program will print out that it is not a multiple.

Code:


#include <iostream>
using namespace std;

int main()
{
    //declaring variables
    double NumberEntered;
    
    //welcome message
    cout << "Welcome to the C++ to find multiples of 2" << endl;
    
    //prompting user
    cout << "Please enter the number you would like to check" << endl;
    
    //read in users answer
    cin >> NumberEntered;
    
    if(NumberEntered%2==0)
    {
        cout << "The number you entered is a multiple of 2" << endl;
    }//if
    
    else
    {
        cout << "The number you entered is not a multiple of 2" << endl;
    }//else
    
    return 0;
    
}//main

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s