fmax=nums[0][0];
if (nums[ROWS][COLS] > max)
max = nums[ROWS][COLS];
cout << max;
system("pause");
return;
}
It outputs the table fine but the max number is way off. I think it has something to do with the fmax at the end of the program. Any help would be useful Thanks
You don't have any code to calculate the max. You simply take the larger of nums[0][0] and nums[10][20]. Since (10,20) is an invalid index for nums, there's no telling what might be there.
Oh, and never under any circumstances use a variable, macro, or function named "max" in your program. Same goes for min. It's stupid, but Microsoft has destroyed the usefulness of those names for everyone with their macros. Any code using those names probably won't build correctly in Visual Studio.....
I'm not going to just give you the answer. However, as a hint, it will resemble the code to output the matrix except with an if statement where the cout is now.
I've already told you the last if statement in the code posted above is bogus. Get rid of it.
It occurs to me that since you've chosen to allocate the 2D array in one contiguous block of memory, you *could* use std::max_element() to help you out here. However, you should probably write manual code first to understand what that would be doing internally.
Bookmarks