First time post and also this is my 3rd program ive written so sorry in advance if i am asking the wrong questions here. So when entering 150.25lbs and 65 in I get 25.002 for my BMI, but I want to round it to 2 decimal places, making it 25.00 BMI. My program displays 25.00 but it must be using the stored value for BMI being 25.002, making it greater than 25.00 and executing the "overweight" if statement. I'm confused about how I can make it so when entering these values it will execute the "normal" if statement. Is there a way I can make a (BMI_R = BMI rounded to 2 decimal places) and use BMI_R in my if else statements?
//This program calculates the users BMI, informs the user of the range they
fall in,
// and the amount of weight they need to gain or lose in order to fall
within the normal range
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float WEIGHT, HEIGHT, BMI, CHANGE_WEIGHT, UPPER_END_WEIGHT, LOWER_END_WEIGHT;
cout << "This program is designed to calculate your Body Mass Index (BMI) using your height and weight \n";
cout << "It will then determine the range that you fall in, and how much \n ";
cout << "weight you must either lose or gain in order to be in the normal range \n";
cout << "\nWhat is your weight in pounds?";
cin >> setprecision(2) >> fixed >> WEIGHT;
cout << "What is your height in inches?";
cin >> setprecision(2) >> fixed >> HEIGHT;
BMI = ((WEIGHT * 703) / (HEIGHT * HEIGHT));
UPPER_END_WEIGHT = (((HEIGHT * HEIGHT) * 25) / 703);
LOWER_END_WEIGHT = (((HEIGHT * HEIGHT) * 18.5) / 703);
cout << "\nYour BMI is " << setprecision(2) << fixed << BMI << endl;
if (BMI < 18.5) {
cout << "You are Underweight \n";
CHANGE_WEIGHT = (LOWER_END_WEIGHT - WEIGHT);
cout << "You must gain " << CHANGE_WEIGHT << " pounds in order to fall in the Normal range \n";
}
else if (BMI >= 18.5 && BMI <= 25.0) {
cout << "You are Normal \n";
}
else if (BMI > 25.0 && BMI <= 30.0) {
cout << "You are Overweight \n";
CHANGE_WEIGHT = (WEIGHT - UPPER_END_WEIGHT);
cout << "You must lose " << CHANGE_WEIGHT << " pounds in order to fall in the Normal range \n";
}
else if (BMI > 30) {
cout << "You are Obese \n";
CHANGE_WEIGHT = (WEIGHT - UPPER_END_WEIGHT);
cout << "You must lose " << CHANGE_WEIGHT << " pounds in order to fall in the Normal range \n";
}
cout << "A normal weight range for the entered height is " << LOWER_END_WEIGHT << "-" << UPPER_END_WEIGHT << "lbs.\n";
cout << "\n*Department of Health and Human Services/National Institutes of Health*\n";
cout << "BMI Values:\n";//Displays information from Department of Health and Human Services/National Institutes of Health for user
cout << "Underweight: less than 18.5 \n";
cout << "Normal: in the interval [18.5, 25.0] \n";
cout << "Overweight: in the interval (25.0, 30.0] \n";
cout << "Obese: greater than 30 \n";
cout << "\n Program written by Dylan O'Neal\n";
cout << " Press [ENTER] to end program";
cin.ignore(256, '\n');
cin.get();
}
Aucun commentaire:
Enregistrer un commentaire