Loop for fraction matrix

Hey. How do I build a matrix by rows and columns, and the values must consist of fractions (asks for each numerator and denominator)? There are errors in the codes below:

Firstly, ask for the values of numerator and denominator.
Secondly, display the matrix that has been built on the screen.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void generateMatrix(vector < vector < tpFraction > > & m)
{	int i, j;
	cout << "Introduce the values of matrix by rows and columns: " << endl;
	for (i = 0; i < m.size(); i++)
		for (j = 0; j < m.size(); j++)
		{	cout << "Introduce the numerator by rows " << i << " and columns " << j << " : ";
			cin >> m[i][j].num;
			cout << "Introduce the denominator by rows " << i << " and columns " << j << " : ";
			cin >> m[i][j].den;
		}
}

void displayMatrix ( vector < vector < tpFraction > > & m ){
    struct tpFraction {
        cout << (m)[i][j] << "\t" ;
};
}


Example:
Generated matrix:
4/3 5/3 -2/3
2/7 8/-9 5/4
0/-3 8/4 -5/4
Last edited on
Topic archived. No new replies allowed.