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.Write("Write starting point of weight in kg: ");
double t2 = double.Parse(Console.ReadLine());

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

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

for (i = BMI; t2 <= t3; 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.

Edited by Realitiez

2 Years
Discussion Span
Last Post by cgeier

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;

Edited by cgeier

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.