## C Programming

### Check the insurance eligibility and calculate premium

#### Objective:

An Insurance company follows the following rules to calculate the premium.

1. If a person’s health is excellent and the person is between 25 and 35 years of age and lives in a city and is a male then the premium is Rs. 4 per thousand and his policy amount cannot exceed Rs. 2 lakhs.
2. If a person satisfies all the above conditions except that the sex is female then the premium is Rs. 3 per thousand and her policy amount cannot exceed Rs. 1 lakh.
3. If a person’s health is poor and the person is between 25 and 35 years of age and lives in a village and is a male then the premium is Rs. 6 per thousand and his policy cannot exceed Rs. 10,000.
4. In all other cases, the person is not insured.

Write a program to output whether the person should be insured or not, his/her premium rate, and maximum amount for which he/she can be insured.

#### Program / Solution:

```#include<stdio.h>
#include<ctype.h>
int main() {
char gen,health,residence;
int age;

printf("Enter the gender male/female (M/F): ");
scanf("%c",&gen);

fflush(stdin);
printf("Enter the health excellent/poor(E/P): ");
scanf("%c",&health);

fflush(stdin);
printf("Enter the residence city/village (C/V): ");
scanf("%c",&residence);

printf("Enter the age: ");
scanf("%d",&age);

//make all inputs in lowercase
//tolower function is already defined in ctype.h
gen = tolower(gen);
health = tolower(health);
residence = tolower(residence);

if(health == 'e' && gen == 'm' && residence == 'c' && (age >= 25 && age <=35)) {
printf("Eligible for insured\n");
printf("Maximum policy amount: Rs. 2 Lakhs\n");
} else if(health == 'e' && gen == 'f' && residence == 'c' && (age >= 25 && age <=35)) {
printf("Eligible for insured\n");
printf("Maximum policy amount: Rs. 1 Lakh\n");
} else if(health == 'p' && gen == 'm' && residence == 'v' && (age >= 25 && age <=35)) {
printf("Eligible for insured\n");
printf("Maximum policy amount: Rs. 10000\n");
}else {
printf("Person is not insured");
}

}
```

#### Sample Output:

```Enter the gender male/female (M/F): m
Enter the health excellent/poor(E/P): e
Enter the residence city/village (C/V): c
Enter the age: 32
Eligible for insured
Maximum policy amount: Rs. 2 Lakhs
```