Thursday 12 April 2012

Lecture: 35


                                                Lecture 35
Conditional Statements (Decision Making)
Code:
//Insurance of driver using logical operators
#include <iostream>
#include <conio.h>
using namespace std;
int main (int argc, char *argv[])
{
  char sex, ms;
  int age;
  cout<<"Enter age in number : "; cin>>age;
  cout<<"Enter Sex (M,F) : "; cin>>sex;
  cout<<"Enter Marital status (U , M) : "; cin>>ms;
  if((ms == 'M') || (ms == 'U' && sex == 'M' && age>30) ||
         (ms == 'U' && sex == 'F' && age>25))
   {
      cout<<"Diriver is insured: ";     
   }
  else if((ms == 'm') || (ms == 'u' && sex == 'm' && age>30) ||
             (ms == 'u' && sex == 'f' && age>25))
   {
      cout<<"Diriver is insured: ";     
   }
   else cout<<"Driver is not insured. ";
  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10