Need help with creating a table

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:

https://imgur.com/a/hKVFm

What I have now infinitely loops and I'm not sure why.

Sorry for the seemingly complicated question. I tried to explain it the best I could. Thanks so much to anyone who can help out.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  #include <iostream>

using namespace 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; 
	}
	
}
Last edited on
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;
}
Last edited on
Topic archived. No new replies allowed.