Which wrong?when i key-in 2/29/2000 display two 1-valid 2nd-invalid somealso display 1-valid 2nd-invalid

#include <iostream>
#include <iomanip>
using namespace std;

int main()

{

int month, day, year;

cout << "Month (January to December)-";
cin >> month;
cout << "Day(1 to 31)";
cin >> day;
cout << "Year( 1990 to 2009)";
cin >> year;

if(cin.fail()) // check input for bad datatype

{

cout << "That's not an valid entry! " << endl;

}

if (month == 2 && day == 29 && (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)))

{

cout << "The date " << month << "-" << day << "-" << year << " is valid." << endl;


}

if (month == 2 && day == 29 && (year % 4 != 0) && ((year % 100 == 0) || (year % 400 != 0)))

{

cout << "The date " << month << "-" << day << "-" << year << " is NOT valid. LEAP YEAR!" << endl;


}

if (month == 1 && day <= 31)

{

cout << "The date " << month << "-" << day << "-" << year << " is valid." << endl;

}

if (month == 2 && day <= 28)

{

cout << "The date " << month << "-" << day << "-" << year << " is valid." << endl;

}

if (month == 3 && day <= 31)

{

cout << "The date " << month << "-" << day << "-" << year << " is valid." << endl;

}

if (month == 4 && day <= 30)

{

cout << "The date " << month << "-" << day << "-" << year << " is valid." << endl;
}

if (month == 5 && day <= 31)

{

cout << "The date " << month << "-" << day << "-" << year << " is valid." << endl;

}

if (month == 6 && day <= 30)

{

cout << "The date " << month << "-" << day << "-" << year << " is valid." << endl;

}

if (month == 7 && day <= 31)

{

cout << "The date " << month << "-" << day << "-" << year << " is valid." << endl;

}

if (month == 8 && day <= 31)
{

cout << "The date " << month << "-" << day << "-" << year << " is valid." << endl;

}
if (month == 9 && day <= 30)

{

cout << "The date " << month << "-" << day << "-" << year << " is valid." << endl;

}

if (month == 10 && day <= 31)

{

cout << "The date " << month << "-" << day << "-" << year << " is valid." << endl;
}
if (month == 11 && day <= 30)
{
cout << "The date " << month << "-" << day << "-" << year << " is valid." << endl;
}
if (month == 12 && day <= 31)
{
cout << "The date " << month << "-" << day << "-" << year << " is valid." << endl;
}
else if ( month == 4 || 6 || 9 || 11 )
{
cout << "THE DATE" " "" < "<< day << "-" << month << "-" << year << ">" "is invalid";
}

return 0;
}
Last edited on
@tang

Your problem lies in this section of code.
 
else if ( month == 4 || 6 || 9 || 11 )


Change it to
 
else if ( month == 4 ||  month == 6 || month ==  9 ||  month == 11 )

and your program will work as intended.
@whitenite thx
Topic archived. No new replies allowed.