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
|
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
HANDLE hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
const int bmi_const=703;
double bmi,
weight,
height,
under,
abs_under,
abs_over,
over;
char again='n';
SetConsoleTextAttribute
(hConsole, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
do
{
cout << "Please enter your weight in pounds: ";
while ( (!(cin >> weight)) | (weight <= 0))
{
cout << "ERROR - Invaild entry. Please reenter your weight in pounds: ";
cin.clear();
fflush(stdin);
}
cout << "\nPlease enter your height in inches: ";
while ( (!(cin >> height)) | (height <= 0))
{
cout << "ERROR - Invaild entry. Please reenter your height in inches: ";
cin.clear();
fflush(stdin);
}
cout << "\nYou weigh " << weight << " pounds, and you are " << height << " inches tall." << endl;
bmi = (weight * bmi_const) / (height * height);
under = ((bmi - 25) / ((height * height) / bmi_const));
abs_under = abs(under);
over = ((18.5 - bmi) * ((height * height)/bmi_const));
abs_over = abs(over);
cout << "Your BMI is: " << bmi << endl;
if (bmi < 18.5)
{
cout << "\nYou are ";
SetConsoleTextAttribute
(hConsole, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
cout << "UNDERWEIGHT";
SetConsoleTextAttribute
(hConsole, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
cout << "." << endl;
cout << "You need to gain " << abs_under << " pounds.";
}
else if ((bmi >= 18.5) && (bmi <= 25))
{
cout << "\nYou are ";
SetConsoleTextAttribute
(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
cout << "NORMAL";
SetConsoleTextAttribute
(hConsole, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
cout << ". Go live a happy life." << endl;
}
else if ((bmi > 25) && (bmi <= 30))
{
cout << "\nYou are ";
SetConsoleTextAttribute
(hConsole, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
cout << "OVERWEIGHT";
SetConsoleTextAttribute
(hConsole, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
cout << "." << endl;
cout << "You need to lose " << abs_over << " pounds." << endl;
}
else if (bmi > 30)
{
cout << "\nYou are ";
SetConsoleTextAttribute
(hConsole, FOREGROUND_RED | FOREGROUND_INTENSITY);
cout << "OBEASE";
SetConsoleTextAttribute
(hConsole, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
cout << "." << endl;
cout << "You need to lose " << abs_over << " pounds." << endl;
}
cout << "\n\n\n\n\t\tThis was programmed by: ";
SetConsoleTextAttribute
(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
cout << "Devon Naccarato";
SetConsoleTextAttribute
(hConsole, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
cout << "." << endl;
cout << "\n\n\nWould you like to calculate someone else's BMI? [Y/N]: ";
cin >> again;
} while(again =='Y' || again =='y');
return 0;
}
| |