Flow chart of the sample program

 

The complete code of the program is given below.

 

# include <iostream.h>

 

main ( )

{

            int AmerAge, AmaraAge;

            //prompt the user to enter Amer’s age

cout << “Please enter Amer’s age  “ ;

            cin >> AmerAge;

            //prompt the user to enter Amara’s age

            cout << “Please enter Amara’s age     “ ;

            cin >> AmaraAge;

            //perform the test

            if (AmerAge > AmaraAge )

                        cout << “ Amer is older than Amara”;

}

 

 

 

 

In our program, we write a single statement with the if condition. This statement executes if the condition is true. If we want to execute more than one statements, then we have to enclose all these statements in curly brackets { }. This comprises a block of statements which will execute depending upon the condition. This block may contain a single statement just like in our problem. So we can write the if statement as follow.

if (AmerAge > AmaraAge )

{

cout << " Amer is older than Amara";

}          

 

 

 

 

Previous

 

 

TOC

 

 

Next