In this example, we'll calculate the insurance eligibility for an individual based on their age and employment status. We'll use if
statements to decide whether they are eligible for insurance or not.
1️⃣ Example: Checking Insurance Eligibility
#include <iostream>
using namespace std;
int main() {
int age;
string employmentStatus;
bool isEligible = false; // Variable to store eligibility status
// Taking inputs
cout << "Enter your age: ";
cin >> age;
cout << "Enter your employment status (Employed/Unemployed): ";
cin >> employmentStatus;
// Eligibility criteria
if (age >= 18 && age <= 60) {
if (employmentStatus == "Employed") {
isEligible = true;
}
}
// Displaying the eligibility result
if (isEligible) {
cout << "You are eligible for insurance." << endl;
} else {
cout << "You are not eligible for insurance." << endl;
}
return 0;
}
Explanation:
-
Age Condition:
The individual must be between 18 and 60 years old (inclusive) to be eligible for insurance. -
Employment Status:
The individual must be employed for insurance eligibility. If they are unemployed, they are not eligible. -
Eligibility:
- If both conditions are met (age between 18 and 60 and employed), the eligibility is set to
true
. - If any of the conditions fail, the eligibility remains
false
.
- If both conditions are met (age between 18 and 60 and employed), the eligibility is set to
2️⃣ Example with Expanded Conditions (Including Senior Citizens)
We can expand the program to include senior citizens (above 60) who can still be eligible for insurance, but under different conditions (like a higher premium). We can also check if someone is under 18 and disqualify them for insurance.
#include <iostream>
using namespace std;
int main() {
int age;
string employmentStatus;
bool isEligible = false;
// Taking inputs
cout << "Enter your age: ";
cin >> age;
cout << "Enter your employment status (Employed/Unemployed): ";
cin >> employmentStatus;
// Eligibility criteria
if (age < 18) {
cout << "You are not eligible for insurance due to age." << endl;
} else if (age <= 60) {
if (employmentStatus == "Employed") {
isEligible = true;
} else {
cout << "You must be employed to be eligible for insurance." << endl;
}
} else {
cout << "You are eligible for insurance, but may have a higher premium due to age." << endl;
isEligible = true;
}
// Displaying the eligibility result for those under 60
if (isEligible) {
cout << "You are eligible for insurance." << endl;
}
return 0;
}
Explanation:
- Under 18: The program directly states that the individual is not eligible for insurance due to their age.
- 18 to 60: Eligibility depends on employment status.
- Above 60: Senior citizens are eligible, but it mentions that they may face higher premiums due to age.
Output 1 (if age = 25 and employmentStatus = "Employed"):
Enter your age: 25
Enter your employment status (Employed/Unemployed): Employed
You are eligible for insurance.
Output 2 (if age = 17):
Enter your age: 17
Enter your employment status (Employed/Unemployed): Employed
You are not eligible for insurance due to age.
Output 3 (if age = 65):
Enter your age: 65
Enter your employment status (Employed/Unemployed): Retired
You are eligible for insurance, but may have a higher premium due to age.
You are eligible for insurance.
3️⃣ Real-World Application:
- Insurance Systems: This type of program could be useful in online insurance applications where users input their details, and the program determines whether they meet the eligibility criteria.
- Eligibility Customization: You could expand this further to consider other factors like health conditions, existing coverage, or income for eligibility determination.
Would you like to enhance this program further to consider additional factors (e.g., health conditions, income) or implement another type of eligibility check?
0 Comments