Recursive adding elements in array

The goal of this program is to take 4 neighboring elements in an array and add them together. The program asks user for the number of rows and columns to start out with and the program will then continue to print the board until 1 element remains.

I'm having problems getting my program to compile (line 19) and I'm sure the logic is wrong. If someone could take a look at it and help it would be greatly appreciated.


#include <iostream>
#include <cstring>
#include <cstdlib> 


//Prototypes for all functions
int **dimension(int, int);
void calc_result_iterative(int, int, int);
void calc_result_recursion(int, int, int, int, int);

using namespace std;

int main(){

int rows, cols, n, row, col;
cout << "How many rows and columns would you like to use? "<<endl;
cin >> n;
int **dim = dimension(n, n);
calc_result_iterative(dim, rows, cols);
//calc_result_reciursion(dim, rows, cols, row, col);

	return 0;
}


void calc_result_iterative(int **dim, int rows, int cols){
	for(int row = 0; row < rows; row++ ){
		for(int col = 0; col < cols; col++){
			cout << dim[row][col] << endl << endl <<endl;
		}
	}


}

void calc_result_recursion(int **dim, int rows, int cols, int row, int col){
	if(col == cols && row == rows-1)
		return;
	if(col == cols){
	col == 0;
	col++;
	cout<< endl<< endl<<endl;
	
	}
	cout << dim[row][col] << " ";
	calc_result_recursion(dim, rows, cols, row+1, col);
}

int **dimension(int rows, int cols){
	int **dim = new int*[rows];
	for(int i = 0; i < cols; i++)
	   dim[i] = new int[cols];
	return dim;
}
1
2
3
void calc_result_iterative(int, int, int);
int **dim = dimension(n, n);
calc_result_iterative(dim, rows, cols);
Do you see some inconsistency here?
When I change the dim argument in the function to a double splat argument it doesn't compile either.
YPu clearly changed it wrong, because it should compile. And post your compile errors. We are not psychics here and cannot read your compiler messages.
Topic archived. No new replies allowed.