i'm trying to create a program that calculates Body mass index in a for loop with 5kg gaps. BMI formula is: weight(kg)/height(meters squared) = BMI. How would this work? this is the code i got so far:

Console.Write("Write your height in meters: ");
double t1 = double.Parse(Console.ReadLine());
Console.Clear();

Console.Write("Write starting point of weight in kg: ");
double t2 = double.Parse(Console.ReadLine());
Console.Clear();

Console.Write("Write ending point of weight in kg: ");
double t3 = double.Parse(Console.ReadLine());
Console.Clear();

double i = t1;
double t1s = t1 * t1;
double BMI = t2 / t1s;

for (i = BMI; t2 <= t3; i++)

Console.WriteLine(i);
t2 += 5;
} Console.ReadKey();

i want the result to look somewhat like this:
BMI for height 1,6m is:
weight | BMI
60 | 23.44
65 | 25.39
70 | 27.34
...skipping to 125(ending point)
125 | 48.83

i'm really lost in how this can work, if anyone knows how this could work please answer.

I recommend using some useful names so it is easier to follow your code. Use something like "height", "startWeight", "endWeight" instead of "t1", "t2", "t3".

I suggest that you use the following form of the for loop:

double startWeight = 60;
double endWeight = 125;

double weight = startWeight;

for (weight = startWeight; weight <= endWeight; )
{
    //rest of your code here


    //increment weight
    weight = weight + 5;
}//for

body mass index problem programing c#

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.