Monday, March 30, 2009

Write an Insurance program with & without && ||

/*A company insures its drivers in the following cases :-

- if the driver is married
- if the driver is unmarried,male & above 30 years of age
-if the driver is unmarried and female & above 25 years of age

In all other cases the driver isnt insured.If marital status ,sex & age of the driver is input ,write a prg to determine whether the driver is to be insured or not */


#include <stdio.h>
int main(void)
{
int age;
char sex,ms; //ms = marital status
printf("Are you married (Y=yes) & (n=no) :");
scanf("%c",&ms);

if ( ms == 'Y')
printf("You are qualified as you are married");
else
{
printf("Enter your sex(M/F)");
scanf(" %c",&sex);
if ( sex == 'M')
{
printf("Enter your age : ");
scanf("%d",&age);
if ( age > 30)
printf("You are qualified for Insurance");
else
printf("Sorry Mr.you are not qualified");
}
else
{
printf("Enter your age : ");
scanf("%d",&age);
if ( age > 25 )
printf("You are qualified for Insurance lady !!!");
else
printf("Sorry gal you are not qualified for Insurance");

}

}
return 0;
}


*Second Method using && ||
============================
#include <stdio.h>
int main(void)
{
int age;
char ms,sex; // ms is marital status
printf("Enter your Age,Sex(M/F),Marital Status (Y/N):");
scanf("%d %c %c",&age,&sex,&ms);

if (( ms == 'Y') || ( ms == 'N') && ( sex == 'M') && ( age > 30) || ( ms == 'N') && ( sex == 'F') && ( age > 25))
printf("You are eligible for Insurance");
else
printf("Sorry no Insurance for you");
return 0;
}




No comments: