1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
/* Program : Determine retirement age to choose based on BMI and Mortality Predictor
Input : Number of staffs, age, gender, height, weight
Output : */
#include <iostream>
#include <iomanip>
using namespace std;
int a=0; int b=0; //counter for number of staff
double calcBMI(double height, double weight){
double BMI, IMB;
BMI = ( weight / (height*height) );
return BMI;
}
char calcMP(double BMI, int age, char gender){
char MP , PM ;
if (BMI>30) //the problem is in here
{
if (age<40)
{
if ((gender=='M') || (gender=='m'))
{MP='A'; a++;}
else
{MP='B'; a++;}
}
else
{
if ((gender=='M') || (gender=='m'))
{MP='B'; a++;}
else
{MP='C'; b++;}
}
}
else if(BMI<=30)
{
if (age<40)
{
if ((gender=='M') || (gender=='m'))
{MP='A'; a++;}
else
{MP='A'; a++;}
}
else
{
if ((gender=='M') || (gender=='m'))
{MP='B'; a++;}
else
{MP='B'; a++;}
}
}
return MP;
}
int main (){
char gender; int age; char MP;
int i, j; double IMB[100]; char PM[100];
cout << "\nHow many staffs you wish to evaluate? " <<endl;
cin >> j;
for (int i=0; i < j; i++)
{
cout << "\n\nPlease enter the following:\n";
double height, weight, BMI;
cout << "Height (in m) : " ; cin >> height;
cout << "Weight (in kg): " ; cin >> weight;
IMB[i]=calcBMI( height, weight);
cout<< "Your BMI is "<< IMB[i]<< endl;
char gender; int age; char MP;
cout << "Gender : "; cin >> gender;
cout << "Age : "; cin >> age;
PM[i]=calcMP(IMB[i], age, gender);
if ((PM [i]=='A')||(PM[i] =='B')){
cout << "Your code is " << MP<< " .Retire at 60."<<endl;}
else{
cout << "Your code is " << MP<< " .Retire at 55."<<endl;}
}
double BMI, height, weight;
cout << "\n\n*Retirement Age Summary*" << endl;
cout << "------------------------------------------------"<<endl;
cout << setw(10) << "Staff" << setw(11) << "BMI" << setw(17) << "MP Code" <<endl;
cout << "------------------------------------------------"<<endl;
for (int i=0; i<j; i++)
{cout << setw(8) << i+1 << setw(13) << IMB[i] << setw(13) << PM[i] << endl;}
cout << "------------------------------------------------"<< endl;
cout << "Total number of staff retire at 60 : " << a <<endl;
cout << "Total number of staff retire at 55 : " << b <<endl;
system ("pause");
return 0;
}
|