Saturday, July 01, 2006

[2/2] Driver Insurance using Logical Operators

This program basically demonstrates the use of "Logical Operators". This particular program has an advantage over the previous logic that used the if else statement.
Also, the number of lines of the program decreases considerably.

A company insures its drivers in the following cases:
- If the driver is married.
- If the driver is unmarried, male and above 30 years of age.
- If the driver is unmarried, female and above 25 years of age.

In all the other cases, the driver is not insured.
If the marital status, sex and age of the driver are the inputs,
write a program to determine whether the driver is insured or not.

#include<stdio.h>
main()
{

char sex,ms;
int age;

printf ("Enter age, sex, marital status:");

scanf ("%d %c %c", &age, &sex, &ms);

if ((ms=='M') || (ms=='U' && sex== 'M' && age>30) || (ms=='U' && sex== 'F' && age>25))

printf ("Driver is insured");
else
printf ("Driver is not insured");

}



You can also download the file at:
Download File

No comments: