int rowSize = 1;
int colSize = 10;
int array[rowSize][colSize];
int accumulator =0;
//FOR INPUT
for( int row = 0; row < rowSize; row++)
{
cout << "ENTER NUM: ";
for( int col = 0; col < colSize; col++)
{
cin >> array[row][col];
if('\n') break;
}
}
//TEST OUTPUT
for(int row =0; row < rowSize; row++)
{
for( int col =0; col < colSize; col++)
{
accumulator = array[row][col] + accumulator;
cerr << array[row][col];
}
}
cerr << endl << accumulator;
OUTPUT:
ENTER NUM: 1 2 3 4
1867469828
Process finished with exit code 0
Will break the loop but not store my values 1 2 3 4.
Its reserving values in unreserved memory can someone please help
me exit the loop when enter is pressed but still store my values before enter is pressed.
When enter is pressed I need the array to stop at that width or column size
Enter Values: 1 2 3 "Enter"
//once enter is pressed i need the values 1 2 3 to be stored
is index's [0][0] [0][1] [0][2] and move to the next row [1][0]
int the array right after enter is pressed.
1.) need a 2D array that will take in input untill "Enter" is pressed on the same first line only.
EX.
Enter Values: 1 2 3 "Enter"
2.)After "enter" is pressed i need the array to store the values 123 and change
indexs from [0][3] to start new row at [1][0] to prompt user for next input.
3.)The array has to have a max input of 10 integers so array[10][10] for each row and column
4.) The issue is stopping the column short of 10 and by moving on to the next row by pressing "enter"
I need a two dimensional array to input matrix integers.
However, after the Enter is pressed for row 0 the width needs to be set.
Im not sure how to do this since arrays have a fixed or constant value
such as array[10][10]
Each example is a new run of the program
("Enter" just example of user pressing Enter)
OUTPUT SHOULD LOOK LIKE
EX. 1
enter row 0 for the matrix: 1 2 3 "Enter"
enter row 1 for the matrix: 0 1 0 "Enter"
enter row 2 for the matrix: 1 0 9 "Enter"
EX.2
enter row 0 for the matrix: 1 2 3 4 5 6 "Enter"
enter row 1 for the matrix: 0 1 0 0 1 0 "Enter"
enter row 2 for the matrix: 1 0 9 0 1 0 "Enter"
EX.3
enter row 0 for the matrix: 1 2 3 4 5 6 7 8 9 1 "Enter"
enter row 1 for the matrix: 0 1 0 0 1 0 1 0 1 1 "Enter"
enter row 2 for the matrix: 1 0 9 0 1 0 1 0 1 0 "Enter"
*The first line prompting for row 0 is setting the width for the matrix. But i cant figure it out
*The first line after enter is pressed is setting up the entire matrix for the amount of integers inputed. Is the more clear?
> However, after the Enter is pressed for row 0 the width needs to be set.
So according to this assignment question, do one need to input the width of the matrix in advance or the width of the matrix will be determined after the first row input?
You need 2 additional integer variables say, column_limit and row_limit which are each determined when the first set of numbers for the row or column are input. Count the number of numbers input in each set.
These two limits then are used to override any future reference to array access in place of rowSize and colSize. Keep in mind both have to be not greater than than those two
Breaking on '\n' and inside an if sounds a bit suspect?