Hello everyone. So, I was given this assignment recently and I am thoroughly stumped. The end goal for the program is to display BMI in a matrix. It has a row at the top for height, starting from minHeight until it reaches maxHeight, and heightStep would be the increment at which this number increases along the row until it reaches maxHeight. The weight variables follow this same pattern. Then, the rows and columns will output the corresponding values using the formula for BMI (weight/height^2). I'm having a hard time formatting my "for" statement to achieve the desired result.
A sample run of my program would look just like this:
#include <iostream>
usingnamespace std;
int main()
{
//Variable Declaration
double minWeight;
double maxWeight;
double weightStep;
double minHeight;
double maxHeight;
double heightStep;
cout << endl;
//The following section is where the user defines the number set they would like to use.
cout << "Please enter minimum weight in kg: ";
cin >> minWeight;
cout << "Please enter maximum weight in kg: ";
cin >> maxWeight;
cout << "Please enter weight step in kg: ";
cin >> weightStep;
cout << "Please enter minimum height in meters: ";
cin >> minHeight;
cout << "Please enter maximum height in meters: ";
cin >> maxHeight;
cout << "Please enter height step in meters: ";
cin >> heightStep;
cout << endl;
for (double i = minWeight; i <= maxWeight; i = i + weightStep)
{
cout << i << endl;
}
for (double j = minHeight; j <= maxHeight; j = j + heightStep)
{
cout << j << endl;
}
}
if you just want to produce output in table form, you need more stuff :)
you probably want
for(all the rows)
{
for(all the columns)
{
cout column with a tab or , or space or something
}
cout end of line
}
here, your inner loop is probably some sort of computation based off the inputs, for each 'cell' entry.
For a dumb example, a table for multiplication up to 5
for(int r = 0; r < 6; r++)
{
for(int c = 0; c < 6; c++)
{
cout << r*c << "\t";
}
cout << endl;
}