Answer to Question #288001 in C++ for Mona

Question #288001

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.


1
Expert's answer
2022-01-17T00:34:19-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment