C++: Error C2664 and Diagonal Sorting

Hello, this is my homework: Create 3 functions, 1 that would create a 2D array and fill it randomly, then the 2nd function to print the Array on the screen, and the 3rd function to sort the array diagonally, and then call back the 2nd function to print the sorted array on screen. I have done all of it, but there's one little problem at line 36. I cant seem to figure out how to fix it. I get the following error :"Error 2 error C2664: 'forsorting' : cannot convert parameter 1 from 'int [6][6]' to 'int []' c:\users\pc\desktop\usb\anthony\documents\visual studio 2012\projects\function 5\function 5\function 5.cpp". I've searched google but i couldnt find what i needed.
Also, I would like to ask if its possible to print the 2 dimensional array diagonally, meaning it would look something like :

1 2 4 7
3 5 8 11
6 9 12 14
10 13 15 16

Thank you very much for your help
Regards


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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
  // HW3 C++.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <math.h>
#include <time.h>
#include<iomanip>
using namespace std;
const int AS=6;
int main()

{
	int funny=0;
int timpa=0;
int counter=0;
int Array[AS][AS];
int filling (void);
void printing (int [AS][AS]);
void forsorting (int [], int);
srand(time(0));

for(int i=0;i<AS;i++)
	{for(int j=0;j<AS;j++)
	Array[i][j]=filling();}

cout<<"The unsorted array is"<<endl<<endl;

printing(Array);


cout<<"The sorted array is"<<endl<<endl;



forsorting(Array[][],funny);





system("PAUSE");


	return 0;

}

int filling (void)
{int kira;
kira=rand()%87+12;
return kira;}


void printing (int Array[AS][AS])
	{int counter=0;
		for(int i=0;i<AS;i++)
	{for(int j=0;j<AS;j++)
	{cout<<setw(5)<<Array[i][j];
counter++;
if (counter%AS==0)
	cout<<endl<<endl;}
}}

int forsorting (int Array[AS][AS], int funny)
{int c, tmp, x;
	int dice=0;
	int Brray[AS*AS];
int timpa=0;
int super=0;

//Transofrming Array[][] into Brray[]
for(int i=0; i<=AS*AS;i++)
{for(int k=0;k<=AS*AS; k++)
{Brray[timpa]=Array[i][k];}
}



for(int passer=1;passer<=AS*AS;passer++)
{for (int timon=1;timon<=AS*AS;timon++)
     {if(Brray[timpa]>Brray[timpa+1])
{super=Brray[timpa];
Brray[timpa]=Brray[timpa+1];
Brray[timpa+1]=super;
}
}
}

for(int e=0;e<AS;e++)
{for (int d=0;d<AS;d++)
{Brray[dice]=Array[e][d];

dice++;}
}
 

for (c = AS - 1; c > -AS; c--) {
    tmp = AS - abs(c) - 1;
    x = tmp;
    while (x >= 0) {
        if (c >= 0) {
            std::cout << Array[x][tmp - x] << ", ";
        }
        else {
            cout << Array[AS - (tmp - x) - 1][(AS-1)-x] << ", ";
        }
        --x;
    }
    cout << "\n";
}
return 0;}
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "stdafx.h"
#include <iostream>
#include <math.h>
#include <time.h>
#include<iomanip>
using namespace std;
const int AS = 6;
int filling(void);
void printing(int[AS][AS]);
int forsorting(int[][AS], int);

int main()

{
	int funny = 0;
	int timpa = 0;
	int counter = 0;
	int Array[AS][AS];
	srand(time(0));

	for (int i = 0; i<AS; i++)
	{
		for (int j = 0; j<AS; j++)
			Array[i][j] = filling();
	}

	cout << "The unsorted array is" << endl << endl;

	printing(Array);


	cout << "The sorted array is" << endl << endl;



	forsorting(Array, funny);





	system("PAUSE");


	return 0;

}

int filling(void)
{
	int kira;
	kira = rand() % 87 + 12;
	return kira;
}


void printing(int Array[AS][AS])
{
	int counter = 0;
	for (int i = 0; i<AS; i++)
	{
		for (int j = 0; j<AS; j++)
		{
			cout << setw(5) << Array[i][j];
			counter++;
			if (counter%AS == 0)
				cout << endl << endl;
		}
	}
}

int forsorting(int Array[AS][AS], int funny)
{
	int c, tmp, x;
	int dice = 0;
	int Brray[AS*AS];
	int timpa = 0;
	int super = 0;

	//Transofrming Array[][] into Brray[]
	for (int i = 0; i <= AS*AS; i++)
	{
		for (int k = 0; k <= AS*AS; k++)
		{
			Brray[timpa] = Array[i][k];
		}
	}



	for (int passer = 1; passer <= AS*AS; passer++)
	{
		for (int timon = 1; timon <= AS*AS; timon++)
		{
			if (Brray[timpa]>Brray[timpa + 1])
			{
				super = Brray[timpa];
				Brray[timpa] = Brray[timpa + 1];
				Brray[timpa + 1] = super;
			}
		}
	}

	for (int e = 0; e<AS; e++)
	{
		for (int d = 0; d<AS; d++)
		{
			Brray[dice] = Array[e][d];

			dice++;
		}
	}


	for (c = AS - 1; c > -AS; c--) {
		tmp = AS - abs(c) - 1;
		x = tmp;
		while (x >= 0) {
			if (c >= 0) {
				std::cout << Array[x][tmp - x] << ", ";
			}
			else {
				cout << Array[AS - (tmp - x) - 1][(AS - 1) - x] << ", ";
			}
			--x;
		}
		cout << "\n";
	}
	return 0;
}



I didn't check the logic just removed the errors
Last edited on
Topic archived. No new replies allowed.