cout << table[row][column];
Are you sure this is what you want to be doing?
In regard to implementing the random integers, you can just assign them as you print that particular cell. So add something before the above code.
On a minor note, why are you creating an array of doubles?
sillyboy
Practically a Master Poster
686 posts since Mar 2007
Reputation Points: 85
Solved Threads: 64
rnum = (rand() % 50) + 1;
if (rnum>1 && rnum <100)
this is not doing quite what you want. rnum will be in the range 1-50. Your if condition will fail on value 1, which should be legitimate.
You're on the right track to get your 1-100 range, and you don't need the if statement.
You need to place the rand( ) statement inside the innermost loop, assigning that value to an array element.
If you choose to do the assignments and display in the same loops, you will also need to add some spacing between the outputs, and output a newline at the after the inner loop completes.
Val
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
okay so the second part of this assingment is: Using a sort routine of your choice, sort the numbers in each of the rows of the array and display the sorted numbers again on 5 lines of 10 numbers each
i have no idea how to do this...in a 2d array. please help!
You can't do this part until you get the first part done. Did you? If so, we can't see the code...
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
you need to change the sort function to sort one column of a two-dimensional array
void sortarrray(int t[][10], int NumRows, int ColToSort)
{
// sort code here
}
>>it also asks me to do a binary search...would it change if its a 2d array?
Very similar to the way you would sort it. Start out using the normal binary search algorithm for a one-dimensional array then expand it to use a 2-dimensional array that searches only one of the columns.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
You have a sort function that will sort a 1D array, it looks to be correct.
In order to sort each row of the 2D array, pass each row to this function.
int i;
for( i = 0; i < 5; i++ )
sort_array( table[i], 10 );
Using just one index with a 2D array is the essentially accessing just that row, treating it as a 1D array.
Of course, you cannot do this with columns. That's a problem for another day.
Val
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
>>Of course, you cannot do this with columns. That's a problem for another day
Sure you can -- if what you mean is you can not sort by columns rather than by rows. Its possible to sort all rows by a specific column or all columns by a specific row. Might not make much sense to do it, but it is possible.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Please, you need more consistent formatting. See this for ideas, especially the use of indentation (TABs vs. SPACES for one)
Also, don't use system("pause") when there are better solutions ...
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
>>Of course, you cannot do this with columns. That's a problem for another day
Sure you can -- if what you mean is you can not sort by columns rather than by rows. Its possible to sort all rows by a specific column or all columns by a specific row. Might not make much sense to do it, but it is possible.
What I meant was that you cannot simply use an individual column as an argument to the sort function that handles a 1D array.
Val
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228