PDA

View Full Version : Greater or equal than and smaller or equal than not working..



ruben.rodrigues
26th April 2011, 10:09
Hi all!

I have this small function that checks a day is between 2 dates.
I give for example as starting date 20/04/2011 and as end date 25/04/2011.
Then I check if the date 22/04/2011 is in between but the operator >= and the <= are not working very well.

Syear = 2011, Eyear = 2011, year = 2011;
Smonth = 04, Emonth = 04, month = 04;
Sday = 20, Eday = 25, day = 22;





if((Syear() >= year) and (Eyear() <= year)){
cout << "Year match" << endl;

if((Smonth() >= month) and (Emonth() <= month)){
cout << "Month match" << endl;

if((_Temp->getSday() >= day) and (_Temp->getEday() <= day)){
cout << "Day match" << endl;
}
}
}


output of the program:

Year Match
Month Match

but day doesn't

then I added this:



if(Sday() >= day) cout << "day >=" << endl;
if(Eday() <= day) cout << "day <=" << endl;


with:
Sday = 20, Eday = 25, day =22;
No output

with:
Sday = 20, Eday = 25, day =20;
output is:
day >=


and with:
Sday = 20, Eday = 25, day =25;
output is:
day <=

that means it only check for days = to Sday or Eday.

What is wrong?

thanks

meazza
26th April 2011, 10:59
You say that Sday = 20, Eday = 25, day = 22;. Correct? Then if that is case the case first kondition is not true here. Sday is not bigger nor equal to day, so day is not a match

if((_Temp->getSday() >= day) and (_Temp->getEday() <= day))

ruben.rodrigues
26th April 2011, 12:17
You say that Sday = 20, Eday = 25, day = 22;. Correct? Then if that is case the case first kondition is not true here. Sday is not bigger nor equal to day, so day is not a match

if((_Temp->getSday() >= day) and (_Temp->getEday() <= day))

correct. I have noticed that a couple of minutes ago. I have to put the day before the Sday and the Eday.

This is what happens when you have 4 days of holydays and the playstation network is down :D

Thanks

SixDegrees
27th April 2011, 08:09
if(Sday() >= day) cout << "day >=" << endl;
if(Eday() <= day) cout << "day <=" << endl;



with:
Sday = 20, Eday = 25, day =22;
No output

In your code, you are treating Sday and Eday as functions (possibly constructors) but in your data example you treat them as integers. If that's really a piece of your code and not just a typing mistake, there's some information missing here.