How to get the min value excluding “zero”

 
I want to get the Minimum value from the following external variables excluding the empty fields.
It could be something like this: A = 1.354; B = 3.762; C = 0.0; D = 0.0 Below the external variables and the formula:
extern double  A = 0.0; 
extern double B = 0.0;
extern double C = 0.0;
extern double D = 0.0;
double MinValue=MathMin(MathMin(MathMin(MathMin(A,B),C),D);
 
ElGaviero:

What does your post have to do with arrays?

 
Keith Watford:

What does your post have to do with arrays?

Sorry you’re right!
Subject updated.. I thought I’d go through array than I changed my mind😅
 
ElGaviero:

Here what I want to get:

the Minimum value from some external variables as in the first post, excluding the empty fields.

It could be something like this: A = 1.354; B = 3.762; C = 0.0; D = 0.0 

So MinValue should return 1.354 instead of 0.0..


Any idea? I know it’s pretty basic but I need your help! Thanks in advance..

 
ElGaviero:

Here what I want to get:

the Minimum value from some external variables as in the first post, excluding the empty fields.

It could be something like this: A = 1.354; B = 3.762; C = 0.0; D = 0.0 

So MinValue should return 1.354 instead of 0.0..


Any idea? I know it’s pretty basic but I need your help! Thanks in advance..

All the time you comapre to 0 you will have a problem so you need to iterate through the values and only do the comparison if the variable is not 0.

example attached, could be done more more efficiently if the values to be checked were stored in an array.

void OnStart()
{
   double   A = 1.123;
   double   B = 0.0;
   double   C = 0.001;
   double   D = 1.1;
     
   double MinValue = 999999999.00;
   
   if(A != 0 && A < MinValue) MinValue = A;
   if(B != 0 && B < MinValue) MinValue = B;
   if(C != 0 && C < MinValue) MinValue = C;
   if(D != 0 && D < MinValue) MinValue = D;
   
   if(MinValue == 999999999.00)
      Print("No value found");
   else
      Print("MinValue = " + MinValue);
}
 
Paul Anscombe:

All the time you comapre to 0 you will have a problem so you need to iterate through the values and only do the comparison if the variable is not 0.

example attached, could be done more more efficiently if the values to be checked were stored in an array.

Thanks for your help Paul, very kindly on you! The problem is that I have to calculate from the same values to be checked the “Max Value” as well! 
A bool type tell us which one to calculate:
bool condition = true; //MaxValue;

Of course my example is just an oversimplification!!

 
ElGaviero:
Thanks for your help Paul, very kindly on you! The problem is that I have to calculate from the same values to be checked the “Max Value” as well! 
A bool type tell us which one to calculate:

Of course my example is just an oversimplification!!

just reuse the code I gave you and change it for Max Value

 
Paul Anscombe:

just reuse the code I gave you and change it for Max Value

I was thinking about a few lines of code less but that’s enough which make it easy to adapt for exacting application requirements. Thanks so much, I really appreciate it!!
 
ElGaviero:
I was thinking about a few lines of code less but that’s enough which make it easy to adapt for exacting application requirements. Thanks so much, I really appreciate it!!

I wouldn't worry about a few lines of code it won't slow your program down relatively

 
int TestArray() {
   int Arr[] = {1000,18,500,315,0,365};
   int x = INT_MAX;
   for(int i = ArraySize(Arr)-1; i >= 0; --i) {
      if(Arr[i]>0 && Arr[i]<x) x = Arr[i];
   }
   return x;
}

should return 18

 
I reworked your lines and now works fine. Thanks again for helping me!
Reason: