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

Demo "if ... else if ... else" Statements

/*This program is used to reward employees for their years of
   faithful service to a teddy bear company.*/

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

int main(void)
{
     system("CLS"); 
     int years;              

     cout<< "\n\nHow many years of"
            << " service? ";
     cin>> years;

     if (years > 20)
    {                      
           cout<<"\nYou get the gold watch teddy bear!!";
     }
     else if (years > 10)        
//you already know years is not > 20 
     {
           cout<<"\nYou get a new paper weight teddy bear"
                  <<" for your desk!!";
     }
     else                                
//you already know years is not >10
     {
           cout<<"\nYou get a great big teddy bear"
                  <<" pat on the back!!";
     }

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

 

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