My function is not checking the IF condition is already going straight into the ELSE

Asked

Viewed 51 times

1

    private int dia;
    private int mes;
    private int ano;

    public bool GravaData(int d, int m, int a)
    {
        if ((d > 0 && d <= 31) && (m > 0 && m <= 12) && (ano > 0))
        {
            dia = d;
            mes = m; 
            ano = a;
            return true;
        }
        else
        {
            return false;
        }
    }
  • 3

    Your problem is here (ano > 0) when it would actually be (a > 0) see working: https://dotnetfiddle.net/SrDIMw

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.