This program calculates the user's body mass index and tells the user whether they are overweight or healthy. I would like to modify the code so the program asks the user for some information (i.e their name), the user enters their name, and then the program asks "what is your weight". Like a human conversion! I only want "what is your weight" displayed after the user has entered in their name.
I'm really happy with this program. It's my first real program that does something useful
/* BMI */
#include <iostream>
usingnamespace std;
main()
{
string first_name; //input
float your_weight_kg; //input
float your_height_metre; //input
float result; //BMI result
cout << "Please enter your First Name\n";
cout << "Please enter your weight in KG (decimal)\n";
cout << "Please enter your height in metres (decimal)\n";
cin >> first_name;
cin >> your_weight_kg;
cin >> your_height_metre;
// BMI formula
result = (your_weight_kg / (your_height_metre * your_height_metre));
//BMI result
if (result > 25){
cout <<"\n""Hello " << first_name << ", you may be overweight. A BMI score of " << result << " indicates you are overweight for your height. The BMI is a guide only and you should consult your doctor for a accurate accessment. ";
}
elseif ( result < 18 ) { /* I use else just to show an example */
cout <<"\n""Hello " << first_name << ", you may be underweight. A BMI score of " << result << " indicates you are underweight for your height. The BMI is a guide only and you should consult your doctor for a accurate accessment. ";
}
else {
cout <<"\n""Hello " << first_name << ", Congratulations! You are a healthy weight. A BMI score of " << result << " indicates you are a healthy weight. Try to maintain this weight.";
}
}
/* BMI */
#include <iostream>
usingnamespace std;
main()
{
string first_name; //input
float your_weight_kg; //input
float your_height_metre; //input
float result; //BMI result
cout << "Please enter your First Name\n";
cin >> first_name;
cout << "Please enter your weight in KG (decimal)\n";
cin >> your_weight_kg;
cout << "Please enter your height in metres (decimal)\n";
cin >> your_height_metre;
// BMI formula
result = (your_weight_kg / (your_height_metre * your_height_metre));
//BMI result
if (result > 25){
cout <<"\n""Hello " << first_name << ", you may be overweight. A BMI score of " << result << " indicates you are overweight for your height. The BMI is a guide only and you should consult your doctor for a accurate accessment. ";
}
elseif ( result < 18 ) { /* I use else just to show an example */
cout <<"\n""Hello " << first_name << ", you may be underweight. A BMI score of " << result << " indicates you are underweight for your height. The BMI is a guide only and you should consult your doctor for a accurate accessment. ";
}
else {
cout <<"\n""Hello " << first_name << ", Congratulations! You are a healthy weight. A BMI score of " << result << " indicates you are a healthy weight. Try to maintain this weight.";
}
}
Also, the user can input whole numbers not necessarily a decimal. It doesn't matter.
Also, the user can input whole numbers not necessarily a decimal.
What do you mean by this? Of course the user can enter decimals, @redback is inputting into a floating point! If I was inputting, all the following inputs for the "your_weight_kg" variable are valid:
-61.5
6141.36183956134
4.614e21
-3.6e-4
EDIT:
Also, please declare main() as type int, return something at the end (probably 0), don't forget to #include <string> at the top of your code and no need to concantenate the "\n" with your
@ NT3:
I meant that the user can also input numbers like 50, 20 15. It doesn't necessarily have to be a decimal. I know the user can input decimals. I told that because the instruction which redback wrote tells the user to input a decimal number. So the user may be confused.