Matrix - need good programmer help

Jul 13, 2016 at 5:54am
*EDIT


cout << "Enter number of integers: ";
cin >> arrray[row][col];


OUTPUT:
Enter number of integers: 1 2 3 4

Say user inputs 1 2 3 4

how can I count the number of integers the user inputed and send it back to the variable col inside the array to be the new column.

-The user inputed a total of 4 numbers
-So now i want to reinitalize during run time the value of col in the array[row][col]

(array[row][4]) for better understanding




Last edited on Jul 13, 2016 at 6:34am
Jul 13, 2016 at 6:04am
Hi,
> I hope i have been pretty clear.
You haven't tried your best to make it clear.

What is the assignment question?

P.S : You may copy & and paste the assignment and show us the problem you are trying to solve.

Everybody here is glad to help when you get off the starting blocks :)
Jul 13, 2016 at 6:25am
So to sum up :
+ Input the number of rows of the matrix
+ Create the matrix (rows == colums)
+ Input value for each matrix element

Am I right?

P.S : You shouldn't have removed your second post. We need it so that we can understand your problem better.
Jul 13, 2016 at 6:31am
closed account (48T7M4Gy)
Definitely a case of obscure clarity but might we be looking at jagged arrays by any chance?

http://www.cplusplus.com/forum/beginner/192261/
Last edited on Jul 14, 2016 at 2:09pm
Jul 13, 2016 at 6:35am
Do you have the code?
Jul 13, 2016 at 6:37am
for(int indexRow = 0; indexRow < ROW_SIZE; indexRow++)
{
cout << "Enter row " << indexRow << " for the 1st matrix: ";

for(int indexCol = 0; indexCol < COL_SIZE; indexCol++)
{
cin >> firstMatrix[indexRow][indexCol];
}
}

the main issue is initializing the array without a constant.
and i want to change the value of the array ROW and COL during run time.

But i get a compile time error because array must have CONST in [const][const]



right now i just have constant values for max col and mac row sizes.

I want to not use constant values and set the size of col and row by user input based on how many integers the user inputs on the first line
Last edited on Jul 13, 2016 at 6:39am
Jul 13, 2016 at 6:44am
Do you use std::vector?
Have you learned pointers?
Jul 13, 2016 at 6:46am
yes i have learned pointers
Jul 13, 2016 at 6:48am
Pointer method is a little bit difficult. Do you want to use this more simple & lazy approach?
Jul 13, 2016 at 6:50am
I want to use whatever approach i just want to know how to accomplish. Both ways maybe or what ever way yuoir willing to help me
Jul 13, 2016 at 6:50am
Ive been playing with pointers and I cant seem to make it work so anything will help that will accomplish the task.
Jul 13, 2016 at 6:52am
So before creating the matrix, the user has to input the number of rows & columns of the matrix?
Jul 13, 2016 at 7:06am
This is the kind of thing im testing

const int ROW = 0;
const int COL = 0;



int *column;
column = (int*) (&COL);

*column = 2;

int array[ROW][*column];

for(int indexRow =0; indexRow < 2; indexRow++)
{
for(int indexCol =0; indexCol < *column; indexRow++)
{
cin >> array[indexRow][indexCol];
}

cout << endl;
}


i need to change value of constant first before i can do anything
Jul 13, 2016 at 7:23am
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int ROWS = 0;
int COLUMNS = 0;
int **array;

cin >> ROWS;
cin >> COLUMNS;

array = new int*[ROWS];

for(int indexRow =0; indexRow < ROWS; indexRow++) array[indexRow] = new int[COLUMNS];

// Input the matrix's elements

// Your code

// Free the array when not needed
for(int indexRow =0; indexRow < ROWS; indexRow++) 
delete [] array[indexRow];

delete [] array;
Topic archived. No new replies allowed.