Program finds size of matrix from entry

I am new to C++ and want to write a code in which the user types in a matrix and the program uses this information to figure out the matrix size ( and then uses the matrix size and elements for further computations later). I would like it so that when the user hits enter, the program moves down to the next row and when the user hits enter twice it signals that they are done entering elements into the matrix (named mountains).

So far this is what I have:

#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
#include <algorithm>
#include <fstream>

using namespace std;

int main(){

char mountains[100][100];

cout<<"Enter matrix:"<<endl;
char ch;
int x=0, y=0, columns=0, rows=0;
int chr;

cin>>mountains[rows][columns];

do{
for (x=0; x<columns; x++){
for (y=0; y<rows; y++){
chr=mountains[x][y];
cin.get(chr);
if (chr='\n'){
columns=columns;
rows=rows+1;
}
else{
columns=columns+1;
rows=rows;
}
}
}
}while (cin.putback(chr)!='\n');

return 0;
}


When I try to compile this I get a bunch of errors back mostly referring to the get and putback actions. Does anyone have any advice on how to correct this? Thanks!

for variable matrix size, dynamic allocated memory can be used. but you should not, because its too complicated for a beginner (2D).

use std::vector instead.
Topic archived. No new replies allowed.