Return to Topic Menu | Computer Science Main Page | MathBits.com | Terms of Use

Demo "if ... else" Statements

//This program thinks EVERYONE loves C++.  :-)

#inlcude <iostream.h>
#include <stdlib.h>

int main(void)
{
     system("CLS"); 
     const int Yes = 1;
     const int No = 0;
     int response = No;  //initialize the variable
                                    // to a zero

     //obtain user information
     cout<<"Do you like C++?" << endl;
     cout<<"(Enter 1 for YES or any other number for NO)";
     cout<<endl;
     cin>>response;

    if (response = = Yes)
    {                      
 
           cout<<"Your choice is 'YES'."<<endl;
           cout<<"You had only one key for the right answer, ";
           cout<<"and you have pressed it.";
     }
     else
    {                      
 
           cout<<"Your choice is 'NO'."<<endl;
           cout<<"Maybe you didn't understand the question.";
           cout<<"Re-run the program and try again, please.";
     }

     cout<<endl<<endl<<endl;
      return 0;
}
 

 

 Return to Topic Menu | Computer Science Main Page | MathBits.com | Terms of Use