replacing variables in function with an array

I am having major issues on my homework... I can't seem to figure out the concept and was wondering if anyone can provide a hint on how to do this. I am suppose to use a code my professor gave us to " use an array of six integers for the table parameters that were input and calculated. This means that most of the functions will have only one parameter, which is an array".

we have the program split into 5 pages. 3 source files and 2 header files. In one of the header files there is this

void outputTable(
int productColumnWidth,
int rowHeaderColumnWidth,
int columnMinimum, int columnMaximum,
int rowMinimum, int rowMaximum);


this is what it is doing

void outputTable(
int productColumnWidth,
int rowHeaderColumnWidth,
int columnMinimum, int columnMaximum,
int rowMinimum, int rowMaximum)
{
columnHeaderLine(
productColumnWidth,
rowHeaderColumnWidth,
columnMinimum, columnMaximum);

// horizontal border line
horizontalBorderLine(
productColumnWidth,
rowHeaderColumnWidth,
columnMinimum, columnMaximum);

// product rows
productRows(
productColumnWidth,
rowHeaderColumnWidth,
rowMinimum, rowMaximum,
columnMinimum, columnMaximum);

// horizontal border line
horizontalBorderLine(
productColumnWidth,
rowHeaderColumnWidth,
columnMinimum, columnMaximum);
}



so I need to put the 6 variables productColumnWidth, rowHeaderColumnWidth, columnMinimum, columnMaximum, rowMinimum, and rowMaximum in an array

Any help is appreciated!
Please use the [code][/code] tags (the <> icon) when posting code.

Perhaps
1
2
3
4
5
6
7
8
void outputTable(int params[6])
{
    columnHeaderLine(
        params[0],
        params[1],
        params[2],
        params[3]);
// etc 


or
1
2
3
4
void outputTable(int params[6])
{
    columnHeaderLine(params);
// etc 


Just make a consistent decision that productColumnWidth is now in params[0] (and so on).
Hello SpookSpore,


PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

It makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.



With out seeing the rest of the program one can only guess at what to do.

The chances are good the the array can be filled at the time of input with something like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main()
{
	constexpr  size_t MAXSIZE{ 6 };

	int colummnNums[MAXSIZE]{};

	std::cout << "\n Enter Productcolumn width: ";
	std::cin >> colummnNums[0];

	std::cout << "\n Enter Row header column width: ";
	std::cin >> colummnNums[1];

        return 0;
}

And you would continue on with the rest of the variables putting it into the rest of the array.

Or do something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
int main()
{
	constexpr  size_t MAXSIZE{ 6 };
	const std::string variableNames[]
	{
		"Product column width",
		"Row header column width",
		"Row minimum",
		"Row maximum",
		"Column minimum",
		"Column Maximum"
	};

	int colummnNums[MAXSIZE]{};

	for (size_t lc = 0; lc <MAXSIZE; lc++)
	{
		std::cout << "\n " << variableNames[lc] << ": ";
		std::cin >> colummnNums[lc];
	}

        return 0;
}

The size of the array of strings is determined by what or how many is between the {}s. Or you could use "MAXSIZE" between the []s.

Hope that helps,

Andy
Topic archived. No new replies allowed.