The question originally specified that a user inputs values for a three by three matrix. A challenge was then put forth to modify the program so that a user can specify the dimensions for the array. I attempted the question and my program works fine, but it only prints out the last values in the form of the array the user specified.
/*three by three matrix
user enters values
outputs these elements
sums all the elements and outputs the result
*/
#include <iostream>
using namespace std;
int main(){
int i, j;
int r, c = 0;
int matrix[r][c];
int sum;
cout << "A matrix, you want to make.Help I shall, \n";
cout << "ROWS: ";
cin >> r;
cout << "COLUMNS: ";
cin >> c;
cout << "Give me the values of the " << r << " X " << c << " matrix in rows first: ";
cout << "\n";
//user inputs the values
for(i = 0; i < r; i++){
for(j = 0; j < c; j++){
cin >> matrix[r][c];
sum = matrix[r][c] + sum;
}
cout << "\n";
}
//outputs the values
for(i = 0; i < r; i++){
for(j = 0; j < c; j++){
cout << matrix[r][c] << " ";
}
cout << "\n";
}
cout << "The sum of all these elements is: " << sum;
return 0;
}