So, this is the logic I am trying to implement:
date120 = date5;
date90 = min(date90,date120);
date60 = min(date60, date90, date120);
date30 = min(date30,date60,date90,date120);
where the min function finds the lowest POSITIVE integer.
And here is how I am looping it:
if(strStatus != "5" && date5 >= 0)
{
date120 = date5;
COUT<<"date30 is "<<date30<<" and date60 is "<<date60<<" and date120 is "<<date5<<" and date90 is "<<date90<<ENDL;
if((date120 < date90) && (date120 >= 0))
{
date90 = date120;
COUT<<"and date90 is "<<date90<<ENDL;
if((date90 < date60) && (date90 >= 0))
{
date60 = date90;
COUT<<"and date60 is "<<date60<<ENDL;
if((date60 < date30) && (date60 >= 0))
{
date30 = date60;
COUT<<"and date30 is "<<date30<<ENDL;
}
}
if((date60 < date30) && (date60 >= 0))
date30 = date60;
}
if((date90 < date60) && (date90 >= 0))
{
date60 = date90;
COUT<<"and date60 is "<<date60<<ENDL;
if((date60 < date30) && (date60 >= 0))
date30 = date60;
}
if((date60 < date30) && (date60 >= 0))
{
date30 = date60;
COUT<<"and date30 is "<<date30<<ENDL;
}
COUT<<"Because there was a 5 and date30 is "<<date30<<" and date60 is "<<date60<<ENDL;
}
And the output in the logs looks like :
date30 is -1 and date60 is -1 and date120 is 15 and date90 is -1
Because there was a 5 and date30 is -1 and date60 is -1
Am I doing something wrong with my logic? Am I missing something logic wise? Is there a simpler way to do this?
Well in regards to @Rob’s anwer, he needs to restrict min to the lowest positive integer, so I suggest you implement a custom min function such as
and then use what @Rob suggests:
Don’t forget to #include <algorithm>
I assume if both numbers are non-positive it doesn’t matter which one is returned.