I am quite new to coding so I apologize for any amateur mistakes. I am attempting to program a problem that can calculate a persons Base Metabolic Rate based upon their gender, height, weight, age, and how much they exercise. In my attempt to do this, I tried to use two if statements. The first if statement says that if they select Male/Female, it will then run the user inputs through a certain algorithm. The second if statement is supposed to be for how often the user exercises. The second input is the one I am having difficult with. I cannot figure out how to multiply the BMR by the amount exercised. A lot of the time, the answer is coming up as 0. I'm really begining to think that my logic is screwed up. I will take any and all critiques, suggestions, advice. I just want to learn!
Thank you.
Here is my code
namespace WindowsFormsApplication9
{
public partial class calorieCalculator : Form
{
double malebmr, femalebmr, calories;
int bmrmult;
string gender, exercise;
double height, weight, age;//variables
public calorieCalculator()
{
InitializeComponent();
}
private void calorieCalculator_Load(object sender, EventArgs e)
{
}
private void calculateButton_Click(object sender, EventArgs e)
{
//get personal information
height = double.Parse(heightTextBox.Text);
weight = double.Parse(weightTextBox.Text);
age = double.Parse(ageTextBox.Text);
//select gender
if (genderList.SelectedIndex != -1)
{
gender = genderList.SelectedItem.ToString();
switch (gender)
{
case "Male":
//perform calculation
malebmr = (weight * 10 + height * 6.25 - age * 5 - 5);
calories = malebmr * bmrmult;
bmrDisplay.Text = ("Your base metabolic rate burns " + calories+ " calories");
break;
case "Female":
femalebmr = weight * 10 + height * 6.25 - age * 5 - 161;
MessageBox.Show("You should eat:" + femalebmr + "calories");
break;
}
}
if (exerciseList.SelectedIndex !=-1)
{
string exercise;
exercise = exerciseList.SelectedItem.ToString();
switch (exercise)
{
case "Light exercise (1–3 days per week)":
bmrmult = (decimal)1.375;
break;
case "Moderate exercise (3–5 days per week)":
bmrmult = (int)1.55m;
break;
case "Heavy exercise (6–7 days per week)":
bmrmult = (int)1.725m;
break;
case "Very heavy exercise (twice per day, extra heavy workouts)":
bmrmult = (int)1.9m;
break;
}
}
}
EDIT: Here are the formulas
if Male
BMR = (10 × weight in kg) + (6.25 × height in cm) - (5 × age in years) + 5
if Female
BMR = (10 × weight in kg) + (6.25 × height in cm) - (5 × age in years) - 161
Little to no exercise Daily kilocalories needed = BMR x 1.2
Light exercise (1–3 days per week) Daily kilocalories needed = BMR x 1.375
Moderate exercise (3–5 days per week) Daily kilocalories needed = BMR x 1.55
Heavy exercise (6–7 days per week) Daily kilocalories needed = BMR x 1.725
Very heavy exercise (twice per day, extra heavy workouts) Daily kilocalories needed = BMR x 1.9
EDIT 2: Here is my updated code!
`using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication9
{
public partial class calorieCalculator : Form
{
double malebmr, femalebmr, calories;
int bmrmult;
string gender, exercise;
double height, weight, age;//variables
public calorieCalculator()
{
InitializeComponent();
}
private void calorieCalculator_Load(object sender, EventArgs e)
{
}
private void calculateButton_Click(object sender, EventArgs e)
{
//get personal information
height = double.Parse(heightTextBox.Text);
weight = double.Parse(weightTextBox.Text);
age = double.Parse(ageTextBox.Text);
//select gender
if (exerciseList.SelectedIndex != -1)
{
string exercise;
exercise = exerciseList.SelectedItem.ToString();
switch (exercise)
{
case "Light exercise (1–3 days per week)":
bmrmult = (int)1.375m;
break;
case "Moderate exercise (3–5 days per week)":
bmrmult = (int)1.55m;
break;
case "Heavy exercise (6–7 days per week)":
bmrmult = (int)1.725m;
break;
case "Very heavy exercise (twice per day, extra heavy workouts)":
bmrmult = (int)1.9m;
break;
}
}
if (genderList.SelectedIndex != -1)
{
gender = genderList.SelectedItem.ToString();
switch (gender)
{
case "Male":
//perform calculation
malebmr = (weight * 10) + (height * 6.25) - (age * 5) - 5;
calories = malebmr * bmrmult;
bmrDisplay.Text = ("Your base metabolic rate burns " + calories + " calories");
break;
case "Female":
femalebmr = weight * 10 + height * 6.25 - age * 5 - 161;
MessageBox.Show("You should eat:" + femalebmr + "calories");
break;
}
}
}
}
}