The basic use of if statement in C++ by using diagrams

Now, I will translate it into C++ program. If you experience this phase, you will know that the computer programing is juat like kind of language the function of which is just like the logic thinking. 

The outputs:

Please enter a whole number: 45
The number you've entered is odd.
Thanks. Bye.

The corresponding codes: 

//input an integer and test whether it even or odd numbers
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
    int number = 0;
    cout << "Please enter a whole number: ";
    cin >> number;
    if (number % 2 == 0){
        cout << "The number you've inputed is even." << endl;
    }else{
        cout << "The number you've entered is odd." << endl;
    }
    cout << "Thanks. Bye.";
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_38396940/article/details/121753387