OK, I hope I "wrapped it correctly, but if not, please advise and I will be sure to do this correctly from here.
I am having issues getting my nesting to work. Can I go this deep? Should I try switches? The program function should return values based on age and gender to "rate".
Thanks in advance!
cougarclaws.
#include <iostream>//I/O
#include <iomanip>//output manipulation library
using namespace std;
const double MALE_AGE_14_16 = .095;
const double FEMALE_AGE_14_16 = .080;
const double MALE_AGE_17_21 = .082;
const double FEMALE_AGE_17_21 = .069;
const double MALE_AGE_22_26 = .074;
const double FEMALE_AGE_22_26 = .058;
const double MALE_AGE_27_30 = .062;
const double FEMALE_AGE_27_30 = .052;
const double ALL_AGES_31_64 = .051;
const double ALL_AGES_65_75 = .062;
const double ALL_AGES_75_OVER = .075;
//function determines current insurance rates based on age and gender
double chart (int currentAge, char gender)
{
double rate = 0;
if (gender == 'M' || 'm')
if (currentAge < 16)
rate = MALE_AGE_14_16;
else if ((currentAge > 17) && (currentAge <= 21))
rate = MALE_AGE_17_21;
else if ((currentAge > 22) && (currentAge <= 26))
rate = MALE_AGE_22_26;
else if ((currentAge > 27) && (currentAge <= 30))
rate = MALE_AGE_27_30;
else if (gender == 'F' || 'f')
if (currentAge < 16)
rate = FEMALE_AGE_14_16;
else if ((currentAge > 17) && (currentAge <= 21))
rate = FEMALE_AGE_17_21;
else if ((currentAge > 22) && (currentAge <= 26))
rate = FEMALE_AGE_22_26;
else if ((currentAge > 27) && (currentAge <= 30))
rate = FEMALE_AGE_27_30;
if (gender == 'O')
if ((currentAge >= 31) && (currentAge <= 64))
rate = ALL_AGES_31_64;
else if ((currentAge > 65) && (currentAge <= 75))
rate = ALL_AGES_65_75;
else if (currentAge > 75)
rate = ALL_AGES_75_OVER;
//test
cout << rate;
return rate;
}
//Inquires for user input and disqualifies underage drivers with a warning and exit
int main ()
{
int currentAge = 0;
double vehValue = 0;
double rate;
double annualPremium = 0;
char gender = ' ';
cout << "Insurance Premium Calculation Program"; cout << endl;
cout << endl;
cout << "Please enter driver's age: ";
cin >> currentAge; cout << endl;
cout << endl;
if (currentAge < 14){
cout << "Sorry this applicant is too young to drive"; cout << endl;
cout << endl << endl;
system ("PAUSE");
return 14;
}
if (currentAge >= 30){
gender = 'O';
rate = chart(currentAge, gender);
}
else if (currentAge < 31)
cout << "Please enter driver's gender (M/F): ";
cin >> gender; cout << endl;
cout << endl;
rate = chart(currentAge, gender);
cout << "Enter the approximate value of your vehicle: ";
cin >> vehValue; cout << endl;
cout << endl;
annualPremium = rate * vehValue;
//test
cout << rate << endl;
cout << fixed << showpoint << setprecision(3);
cout << annualPremium << endl;
cout << endl << endl;
system ("PAUSE");
return 0;
}