❔ I need your help with this project BMI & BMR

I am super confused about this project and I don't seem to make any progress or going forward with it.
41 Replies
Buddy
Buddy2y ago
$details
MODiX
MODiX2y ago
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, and what you expect the result to be. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
The king of kings
Ok Please Rust save me from a headache! I am so confused about the gender
1. BMI
First, the program must calculate the BMI-Body Mass Index. BMI is a measure of the ratio between weight and height.
This measurement is used, among other things, by the WHO (World Health Organization) to define overweight/obesity and should be seen as a guideline.
The formula for calculating BMI is as follows:

BMI = 1.3*weight(kg)/height(m)2.5

The program should print whether the person has a normal weight or not according to the following table.

BMI table
The table below applies to men and women over 18 years of age with a normal build.

BMI under 18.5 underweight
BMI 18.5–25 healthy and normal weight
BMI 25–30 overweight
BMI 30–40 severely overweight
BMI over 40 extreme obesity
1. BMI
First, the program must calculate the BMI-Body Mass Index. BMI is a measure of the ratio between weight and height.
This measurement is used, among other things, by the WHO (World Health Organization) to define overweight/obesity and should be seen as a guideline.
The formula for calculating BMI is as follows:

BMI = 1.3*weight(kg)/height(m)2.5

The program should print whether the person has a normal weight or not according to the following table.

BMI table
The table below applies to men and women over 18 years of age with a normal build.

BMI under 18.5 underweight
BMI 18.5–25 healthy and normal weight
BMI 25–30 overweight
BMI 30–40 severely overweight
BMI over 40 extreme obesity
The program will then calculate the BMR-basal metabolic rate. BMR is the daily energy requirement needed to maintain
a person's vital organs at total rest.

One of the formulas that can be used to calculate this is the Mifflin-st Jeor equation:

Men:

BMR (men) = 66.47 + (13.75 × weight in kg) + (5.003 × height in cm) − (6.755 × age in years)

Women:

BMR (women) = 655.1 + (9.563 × weight in kg) + (1.85 × height in cm) − (4.676 × age in years)

Your program should prompt the user to enter their gender, height and weight, and age.

The program must verify that entered values are valid.
50 [cm] ≤ length ≤ 220 [cm] // user's height
10 [kg] ≤ weight ≤ 250 [kg] // user's weight
18 [years] ≤ age ≤ 70 [years] // user's age
The program should then print both bmi and bmr.
The program will then calculate the BMR-basal metabolic rate. BMR is the daily energy requirement needed to maintain
a person's vital organs at total rest.

One of the formulas that can be used to calculate this is the Mifflin-st Jeor equation:

Men:

BMR (men) = 66.47 + (13.75 × weight in kg) + (5.003 × height in cm) − (6.755 × age in years)

Women:

BMR (women) = 655.1 + (9.563 × weight in kg) + (1.85 × height in cm) − (4.676 × age in years)

Your program should prompt the user to enter their gender, height and weight, and age.

The program must verify that entered values are valid.
50 [cm] ≤ length ≤ 220 [cm] // user's height
10 [kg] ≤ weight ≤ 250 [kg] // user's weight
18 [years] ≤ age ≤ 70 [years] // user's age
The program should then print both bmi and bmr.
The BMI one is not asking for gender/ older either, but BMR is asking for gender, height, weight and age. It seems like there is very confusion in this project 🙆🏻‍♂️ 🤷🏻‍♂️ Combining these two programs seems complicated to me at least Did I provide too much details and this led to confuse you or are you busy right now? 🙂
Anton
Anton2y ago
well make them input if they want bmr or bmi first and then ask them for the data you need or make them input all data and then output both metrics if you need both what's the confusion with the age?
Anton
Anton2y ago
or the gender it just dictates which formula to use
The king of kings
This is my code so far
Anton
Anton2y ago
$code
MODiX
MODiX2y ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
Anton
Anton2y ago
please format your code
The king of kings
BlazeBin - ogufedgmequs
A tool for sharing your source code with the world!
The king of kings
So you mean the user input should be either BMI or BMR?
Anton
Anton2y ago
reformat your code pls idk ask the teacher what they want
Anton
Anton2y ago
then do both input then do both
The king of kings
But that's why I posted the thread, it's very confusing. Read above on why ☝️
Anton
Anton2y ago
well take all data you need and then calculate both why is that confusing
The king of kings
Ok BMI table The table below applies to men and women over 18 years of age with a normal build. BMI is combining the man and woman BMR is separating the man from the woman, what the hell 🤷🏻‍♂️
Angius
Angius2y ago
Easiest way to go about would be something like
Console.WriteLine("BMI or BMR?");
var input = Console.ReadLine().ToUpper();
if (input == "BMI")
RunBmi();
else if (input == "BMR");
RunBmr();
else
Console.WriteLine("What?");
Console.WriteLine("BMI or BMR?");
var input = Console.ReadLine().ToUpper();
if (input == "BMI")
RunBmi();
else if (input == "BMR");
RunBmr();
else
Console.WriteLine("What?");
The king of kings
Ok! Great. Thanks a lot. Please! I've been in this project like for over two weeks and I don't understand why they combine BMI with BMR shouldn't they be two separated programs from each other? Based on your understanding.
Angius
Angius2y ago
I mean, maybe? But you can easily have both in the same app So no strong opinions one way or another
The king of kings
Ok Ok! Easy to say, but how can I do that?
MODiX
MODiX2y ago
Angius#1586
Easiest way to go about would be something like
Console.WriteLine("BMI or BMR?");
var input = Console.ReadLine().ToUpper();
if (input == "BMI")
RunBmi();
else if (input == "BMR");
RunBmr();
else
Console.WriteLine("What?");
Console.WriteLine("BMI or BMR?");
var input = Console.ReadLine().ToUpper();
if (input == "BMI")
RunBmi();
else if (input == "BMR");
RunBmr();
else
Console.WriteLine("What?");
React with ❌ to remove this embed.
The king of kings
This one looks clear
Angius
Angius2y ago
RunBmi() runs the BMI "sub-app", asks for input, does calculation, returns output RunBmr() runs the BMR "sub-app", asks for input, does calculation, returns output
The king of kings
This is where I feel stuck and confused
Angius
Angius2y ago
Why? Treat BMI and BMR as their own thing BMI only wants height and weight? Cool, ask only for those! BMR also wants age and gender? Cool, ask for those, height, and weaight
The king of kings
Ok! Great. You made it a bit easy for me to understand what's going on. I'll try to implement thus based on your algorithm. It seems like I would need to create two methods
public static void RunBmi()
{

}
public static void RunBmr()
{

}
public static void RunBmi()
{

}
public static void RunBmr()
{

}
Angius
Angius2y ago
Yep
The king of kings
Ok! But should they stay empty or what?
Anton
Anton2y ago
lol
The king of kings
I'm trying lol, but it's confusing for a beginner, I know you're really good at coding, I just haven't reached your level yet.
Anton
Anton2y ago
are you seriously askikg if they should be empty or are you just joking? because it's obvious that if they're empty they'll do nothing
The king of kings
Yes, I know they shouldn't be empty. I know I should do the calculation for BMI inside of the method signature
Anton
Anton2y ago
inside the body*
The king of kings
Yes
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
The king of kings
No solved yet
Tvde1
Tvde12y ago
it's not how double.TryParse works it returns a boolean and has an out parameter which contains the double $tryparse
MODiX
MODiX2y ago
The TryParse pattern is considered best practice of parsing data from a string: - a TryParse method returns true or false to inform you if it succeeded or not, so you can use it directly in a condition, - since C# 7 you can declare a variable that will be used as an out argument inline in an argument list, - it forces you to check if the out argument contains valid data afterwards, Avoid: Convert.ToInt32 — it's a bad choice for parsing an int. It exists only for backwards compatibility reasons and should be considered last resort.
return Convert.ToInt32(null); //returns 0. null should not be considered as 0 ever
return Convert.ToInt32("asdf"); //throws FormatException
return Convert.ToInt32(null); //returns 0. null should not be considered as 0 ever
return Convert.ToInt32("asdf"); //throws FormatException
(Note: Convert does contain useful conversion methods: To/FromBase64String, To/FromHexString, ToString(X value, int toBase), ToX(string? value, int fromBase)) Avoid: int.Parse — you have to use a try/catch statement to handle invalid input, which is a less clean solution.
var number = int.Parse("abc"); //throws FormatException
var number = int.Parse(""); //throws FormatException
var number = int.Parse("abc"); //throws FormatException
var number = int.Parse(""); //throws FormatException
Use int.TryParse https://docs.microsoft.com/en-us/dotnet/api/system.int32.tryparse?view=net-5.0#System_Int32_TryParse_System_String_System_Int32__
if (int.TryParse(someInput, out var result))
{
Console.WriteLine($"Thanks for giving me the following number: {result}!");
}
else
{
Console.WriteLine("You didn't give me a valid number :c");
}
if (int.TryParse(someInput, out var result))
{
Console.WriteLine($"Thanks for giving me the following number: {result}!");
}
else
{
Console.WriteLine("You didn't give me a valid number :c");
}
Int32.TryParse Method (System)
Converts the string representation of a number to its 32-bit signed integer equivalent. A return value indicates whether the operation succeeded.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.