13. An insurance company insured their driver in following case: - (i)Driver is
married, (ii)Driver is unmarried male and above 30 year (iii) Driver is unmarried
female and above 25 years. In all other cases the driver will not be insured. Write
a program to check whether a driver is insured or not on the basis of marital
status, sex and age.
#include <iostream>
using namespace std;
int main() {
int age; bool isMarried; string gender; string married; bool isMale; bool isFemale;
cout << "Please enter your age: ";
cin >> age;
while (married != "y" || married != "n") {
cout << "Are you married [y/n]: ";
cin >> married;
if (married == "y") {
isMarried = true;
break;
} else if (married == "n") {
isMarried = false;
break;
}
}
while (gender != "m" || gender != "f") {
cout << "Enter your gender [m/f]: ";
cin >> gender;
if (gender == "m") {
isMale = true;
break;
} else if (gender == "f") {
isFemale = true;
break;
}
}
if (isMarried) {
cout << "Eligible for insurance." << endl;
} else if (isFemale && !isMarried && age > 25) {
cout << "Eligible for insurance." << endl;
} else if (isMale && !isMarried && age > 30) {
cout << "Eligible for insurance." << endl;
} else {
cout << "Not eligible for insurance." << endl;
}
return 0;
}
Comments
Leave a comment