Though I would be able to figure this out but for some reason my if statements are just not working. What I'm trying to do is date validation. I call this function passing in day, month, year. The issue I'm having the the if statement. I can't seem to get the symbol / && / || in the order to return what I want. Which is if the month is 1 and day falls between 1-31 return true if not false.

bool isDateValid(int& d, int& m, int& y)
{
   if(m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12 && d<1 || d>31)
     {return false;}

    else if( m==4 || m==6 || m==9 || m==11 && d<1 || d>30)
     {return false;}

    else{return true;}
}

I know I left of Feb but I need to do other stuff for that month.

The "&&" operator has higher precedence than the "||" operator. Your statement in line 3 is evaluating

m==12 && d<1

first, and then running the "||" evaluations.

Can you see how this isn't what you wanted?

Make 2 IF statements so it's more readable. If month { if day } Or put the number of days in an array and a simple

if (d <= MonthDays[m])

makes the job painless and readable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.