samedi 16 juin 2018

c++ if check doesn't work proprely

I am tring to make a day counter which counts the days between two dates but the check doesn't work as i would like to. The problem is that it passes any value I give it for example it thinks there are 41 days in one month. Thank you for your help!

cout << "Please give the two dates!\n";
    cin >> year1 >> m1 >> d1 >> year2 >> m2 >> d2;

    if (1 <= year1 <= 9999 &&
        1 <= year2 <= 9999 &&
        1 <= m1 <= 12 &&
        1 <= m2 <= 12 &&
        1 <= d1 <= 31 &&
        1 <= d2 <= 31 )
    {
        cout << "ok";
    }
    else
    {
        cout << "notOK";
    }

Aucun commentaire:

Enregistrer un commentaire