I'm getting weird output from this program, its printing a bunch of huge negative numbers, they're all the same number in fact. I have no idea what's wrong with it. Heres what im trying to do:

I'm taking ordered pairs and translating it into a boolean matrix so for example input:
1 1
1 2
2 2
3 1
3 3

to this table:

(1) (2) (3)
(1) 1 1 0
(2) 0 1 0
(3) 0 0 1

* parenthesis numbers are the row and column numbers

* a 1 is placed to an ordered pair specified. If the ordered pair is not specified, its a 0

I'm starting with an initial matrix initialized with all the indexes at 0, which is sent to the MatrixConverter function. For all the indicated ordered pairs, the index is changed from 0 to 1. Finally, I want to print that calculated array out. Theres alot more I have to do with this program, but for now I would at least like to nail this part down before I continue.

#include <iostream>
#include <iomanip>
using namespace std;

void MatrixConverter(int x[3][3]);
void MatrixPrinter(int x[3][3]);

int main()
{
	int Matrix_A[3][3] = {{0}} ; 

	MatrixConverter(Matrix_A);

	return 0;
}

void MatrixConverter(int x[3][3])
{
	int C[3][3];
	int NumPairs;

	int k;
	int j;

	cout <<"Enter the number of ordered pairs? ";
	cin >> NumPairs;
	cout << endl;

	for(int i = 0; i < NumPairs; i++)
	{
		cout << "Enter first element of ordered pair " << i + 1 << ": ";
		cin >> k;

		cout << "Enter second element of ordered pair " << i + 1 << ": ";
		cin >> j;

		cout << endl;

		C[k-1][j-1] = 1;
	}
	
	MatrixPrinter(C);
}

void MatrixPrinter(int x[3][3])
{
	for(int i = 0; i < 3; i++)
	{
		for(int j = 0; j < 3; j++)
			cout << x[i][0];
			cout << x[i][1];
			cout << x[i][2];
			cout << endl;
	}
}

Ok so I figured it out, its because my C[3][3] in the for loop wasn't initialized. But now my problem is how do I read the C array after all the calculations have been done and the specified ordered pair spots are changed to 1?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.