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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#include <iostream>
using namespace std;
void displayMenu()
{
cout << "*-------------------------------------*" << endl;
cout << "| BMI Calculator |" << endl;
cout << "|=====================================|" << endl;
cout << "| Select: |" << endl;
cout << "| 1 => Display Data |" << endl;
cout << "| 2 => Insert Data |" << endl;
cout << "|-------------------------------------|" << endl;
cout << "| 3 => Calculate Standard BMI |" << endl;
cout << "| 4 => Clear Data |" << endl;
cout << "|-------------------------------------|" << endl;
cout << "| Q => Quit |" << endl;
cout << "*-------------------------------------*" << endl;
cout << endl;
cout << "Choice: ";
}
void DisplayData( string &name, float &weight, float &height,float &bmi )
{
cout << endl;
cout << "Name = " <<name<< endl;
cout << "Weight = " <<weight<< endl;
cout << "Height = " <<height<< endl;
cout << endl;
}
void InsertData( string &name, float &weight, float &height,float &bmi )
{
cout << endl;
cout<<"Please Enter Your Name\n";
cin >>name;
cout <<"Enter your weight in Kilograms (KG) : ";
cin >> weight;
cout <<"\nEnter your height in Meters (M) : ";
cin >> height;
cout<<"You are now able to calculate your BMI."<<endl;
}
void Calculate( string &name, float &weight, float &height,float &bmi )
{
bmi = weight/(height*height);
cout<<"Your BMI is: "<<bmi<<endl;
if (bmi <= 18.5)
cout << "You are under weight."<<endl;
else if ((bmi > 18.5 ) && (bmi < 25))
cout << "Your weight is in the normal range."<<endl;
else if (bmi >= 25)
cout << "You are overweight."<<endl;
}
void setPrecision ()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(1);
}
void DebugCalculator(string name, float weight, float height)
{
if(name == "null" && weight==0 && height ==0 )
cout<<"Please Insert Your Data Before You Calculate Your BMI Or Your Data is Invalid."<<endl;
}
int main()
{
string name = "null";
float weight = 0 ;
float height = 0;
char choice;
bool invalid = true;
do
{
float bmi;
{
displayMenu();
cin >> choice;
choice = toupper(choice);
switch (choice)
{
case '1' : DisplayData(name, weight, height, bmi);
break;
case '2' : InsertData( name, weight, height, bmi);
break;
case '3' : DebugCalculator(name,weight,height);
setPrecision();
Calculate( name, weight, height, bmi);
break;
case '4' : DisplayData(name="null", weight=0,height=0,bmi);
cout << "Your record have been deleted, please insert your data again." << endl;
break;
case 'Q' : invalid = false;
cout<<"Thanks for using"<<endl;
break;
default : cout << "Invalid selection, try again!" << endl;
}
}
}while(invalid);
cout << "Good bye and have a nice day!" << endl;
cout << endl;
system("PAUSE");
return 0;
}
|