sparkythetiger
Programmer
I ran into a problem while trying to write a matrix program. Basically, what I'm trying to do is make a function INPUT that inputs a matrix from the user. I am having a lot of trouble with the const term at the beginning. Here is what I have so far. Is there any way you can help me?
#include <iostream>
using namespace std;
const int size = 10; // *THIS LINE HAS CAUSED MANY ERRORS
void INPUT( double[][ size ], int, int );
void OUTPUT( double[][ size ], int, int );
int main()
{
char stay = 'y';
int i, j;
int A[ i ][ j ]; // *SAME FOR THIS ONE
cout << "This program manipulates matrices." << endl;
while ( stay == 'y' ) {
cout << "How many rows?";
cin >> i;
cout << "How many columns?";
cin >> j;
INPUT( A, i, j ); // *WHY DOES THE COMPILER SAY i AND j
OUTPUT( A, i, j ); // ARE SUPPOSED TO BE CONSTANTS???
cout << "Enter the number of what you want to do:" << endl << endl
<< "1) Add a single variable to the matrix"
<< "2) Subtract a single variable from the matrix"
<< "3) Add another matrix to the matrix"
<< "4) Subtract another matrix from the matrix"
<< "5) Multiply by another matrix" << endl << endl;
cin >> object;
switch ( object ) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
default:
cout << "Incorrect number.. Enter 1, 2, 3, 4, or 5!" << endl;
continue;
}
cout << endl << "Do you wish to continue with a new matrix? (y or n)" << endl;
cin >> stay;
cout << endl;
}
return 0;
}
void INPUT( double M[][ size ], int r, int c)
{
for( int i = 0; i < r; i++ ) {
for( int j = 0; j < c; j++ )
cout << "Enter array element at row " << i
<< " and at column " << j << " ";
cin >> M[ i ][ j ];
}
}
void OUTPUT( double M[][ size ], int r, int c )
{
for( int i = 0; i < r; i++ ) {
for( int j = 0; j < c; j++ )
cout << M[ i ][ j ] << " ";
cout << endl;
}
}
#include <iostream>
using namespace std;
const int size = 10; // *THIS LINE HAS CAUSED MANY ERRORS
void INPUT( double[][ size ], int, int );
void OUTPUT( double[][ size ], int, int );
int main()
{
char stay = 'y';
int i, j;
int A[ i ][ j ]; // *SAME FOR THIS ONE
cout << "This program manipulates matrices." << endl;
while ( stay == 'y' ) {
cout << "How many rows?";
cin >> i;
cout << "How many columns?";
cin >> j;
INPUT( A, i, j ); // *WHY DOES THE COMPILER SAY i AND j
OUTPUT( A, i, j ); // ARE SUPPOSED TO BE CONSTANTS???
cout << "Enter the number of what you want to do:" << endl << endl
<< "1) Add a single variable to the matrix"
<< "2) Subtract a single variable from the matrix"
<< "3) Add another matrix to the matrix"
<< "4) Subtract another matrix from the matrix"
<< "5) Multiply by another matrix" << endl << endl;
cin >> object;
switch ( object ) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
default:
cout << "Incorrect number.. Enter 1, 2, 3, 4, or 5!" << endl;
continue;
}
cout << endl << "Do you wish to continue with a new matrix? (y or n)" << endl;
cin >> stay;
cout << endl;
}
return 0;
}
void INPUT( double M[][ size ], int r, int c)
{
for( int i = 0; i < r; i++ ) {
for( int j = 0; j < c; j++ )
cout << "Enter array element at row " << i
<< " and at column " << j << " ";
cin >> M[ i ][ j ];
}
}
void OUTPUT( double M[][ size ], int r, int c )
{
for( int i = 0; i < r; i++ ) {
for( int j = 0; j < c; j++ )
cout << M[ i ][ j ] << " ";
cout << endl;
}
}