int o = 45341;
int x = 600;
int b = 802;
int d = 230;
int t = 1000;
int y = 424;
int z = 432;
void Form1::Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
if (abs(x - z) < o)
o=abs(x - z);
if (abs(b - z) < o)
o=abs(b - z);
if (abs(d - z) < o)
o=abs(d - z);
if (abs(t - z) < o)
o=abs(t - z);
if (abs(y - z) < o)
o=abs(y - z);
int oo1;
int oo2;
oo1 = z+o;
oo2 = z-o;
this->label24->Text = oo1.ToString();
this->label25->Text = oo2.ToString();
this->label26->Text = o.ToString();
}
This code will give me the closest number to z, but what if i want to get the 2nd closest number? Anyone have any ideas on how i can do this?
Repeat the algorithm using the closest value to z as z. But in practice you should add all those into a System::List<int> collection and sort! Then find in the collection the closest number to z. The second closest is iether the next to the closest, or the previous to the closest.
Which part you need help with? For repeating the algorithm you would just copy/paste that code, and re-run all those if's of yours, but before you run for the second time, you do z = oo1 (or oo2, check you code; side note: You should use more meaningful variable names).