Problem with dynamic massive using indexes (C++)

closed account (i1ApDjzh)
Hello, everybody! I have a problem with dynamic massive. My task was to find the multiplication of positive matrix elements with using indexes and seperated compiling.
Compiler doesn't warn me about any mistake, but result is not right, it is even not a number.
Can someone tell me what did I do wrong here?

Header.h
1
2
3
4
#include <iostream>
#include <math.h>
using namespace std;
float multi(int k, int t, float **p);


Source1.cpp
1
2
3
4
5
6
7
8
9
10
#include "Header.h"

float multi(int k, int t, float **p)
{
	float w = p[0][0];
	for (int i = 0; i<k; i++)
	for (int j = 0; j<t; j++)
	if (p[i][j]>0) w = w*p[i][j];
	return w;
}


Source.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "Header.h"

int main()
{
		int m, n;
		float **r;
		cin >> m >> n;
		r = new float*[m];
		for (int i = 0; i < m; i++)
			r[i] = new float[n];
		for (int i = 0; i < m; i++)
		for (int j = 0; j < n; j++)
			cin >> r[i][j];
		cout << "\nMultiplication " << multi << endl;
		for (int i = 0; i < m; i++)
			delete[]r[i];
		delete[]r;
		system("pause");
		return 0;
}
Last edited on
You do not call your function at all.
http://www.cplusplus.com/doc/tutorial/functions/
closed account (i1ApDjzh)
Don't I call it in Source1.cpp?
Source1.cpp does not have any calls. It has function definition. Look at line 14 in main()
closed account (i1ApDjzh)
Such a way? It still doesn't work...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "Header.h"

int main()
{
		int m, n;
		float **r;
		cin >> m >> n;
		r = new float*[m];
		for (int i = 0; i < m; i++)
			r[i] = new float[n];
		for (int i = 0; i < m; i++)
		for (int j = 0; j < n; j++)
			cin >> r[i][j];
                        multi (m, n, r);
		cout << "\nMultiplication " << multi << endl;
		for (int i = 0; i < m; i++)
			delete[]r[i];
		delete[]r;
		system("pause");
		return 0;
}
Now line 14 calls your functin and throws out the result.
Line 15 still does not call anything.
Topic archived. No new replies allowed.