How we can use simple if and else statement in c++ code


In if and else statement we make condition and if the condition will be true than the statement of that condition will run. If the if condition will false than run else statement.
Below you can see the code how we can use simple if and else statement. In this code we make a object of any data type and input that object and use in the if and else condition.

Code:


#include <iostream>
#include <string>
using namespace std;
int main() {
    int num;
    cout<<"Enter a number : ";
    cin>>num;
    if(num>60)
    {
                cout<<"How are you. ";
                }
                else
                {
                                cout<<"You should fine. ";
                }
}

Output:


When we enter  53, the number  53 is lesser than the number  60 then it will give “You should fine.” in the output. Below you can see the output when we enter 53.

Enter a number : 53
You should fine.

When we enter  90, the number  90 is greater than the number  60 then it will give “How are you.” in the output. Below you can see the output when we enter 90.

Enter a number : 90


avatar
AUTHOR: Muhammad Abbas
I am Software Engineer.

0 Comments