I have a two-dimensional array of random integers that are in an array of
textboxes. I found the maximum and brought it to Label1. Everything works. But I
still need to colour the textbox in which this maximum is located. I had
versions, but unsuccessful. Please help, who knows where the error is?
int max = Convert.ToInt32(t[0, 0].Text);
for (i = 0; i < x; i++)
{
Hi! Look, there is no error, but the program works incorrectly. I want to
find the Textbox with the maximum value and colour it. But the program colours 3
and more textboxes and i dont now why. I need only one coloured textbox with the
max value.
I see The problem is you
color the TextBox every time you find a new maximal value. It takes multiple
guesses to find the maximal value and you can be sure there is no larger value
only when both loops finish.
You need to use 2 loops to find the maximal value and then 2 different loops
to color every TextBox having this value (coz there can be more of them). Your
code should look something like this:
// find the maximumint max = Convert.ToInt32(t[0, 0].Text);
for (i = 0; i < x; i++)
for (j = 0; j < y; j++)
if (Convert.ToInt32(t[i, j].Text) > max)
max = Convert.ToInt32(t[i, j].Text);
// write the maximum
label1.Text = max.ToString();
// color all cells with the maximumfor (i = 0; i < x; i++)
for (j = 0; j < y; j++)
if (Convert.ToInt32(t[i, j].Text) == max)
t[i, j].BackColor = Color.Red;
Good morning guys! Our portal careerbooster.com reviews follow all the needed stages to
create annotated bibliography and make it complete and credible. Rely on our
writing masters and get everything on time without delays, errors, or
plagiarism!