inputting dates and validating dates.

Hello!!
I am working on a program in which you input three integers and then asks to checkif they are valid dates. I have been working on this code for a while and I cant seem to figure out what i am doing wrong. I'm trying to learn as best I can. If anyone could please look at my code and help me figure out what i am doing wrong. i keep getting this error message saying daysInMonthIs31' : undeclared identifier. I know I am still missing some stuff but i cant figure out what and where. So i would really apprecite any help i can get. thank you.



#include<iostream>
#include<string>

using namespace std;

const int MINIMUM_MONTH_IN_YEAR = 1;
const int MAXIMUM_MONTH_IN_YEAR = 12;




int main(void)
{
// 1. Input
cout << "Enter a date as three numbers separated by spaces <month, day, year>: ";
int month;
int day;
int year;
cin >> month >> day >> year;
cin.ignore(99, '\n');

if ( month < MINIMUM_MONTH_IN_YEAR || month > MAXIMUM_MONTH_IN_YEAR )
{
cout << endl << "This is not a valid date.";
cin.ignore(99,'\n');
return 1;
}
// Process

// Determine if its a leap year.
if (month == 2 && day == 29 && (year%4 == 0) && ((year%100 !=0) || (year% 400 == 0)))

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



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



if ( month == 4 && day <= 30)
if ( month == 6 && day <= 30)
if ( month == 9 && day <= 30)
if ( month == 11 && day <= 30)




if ( month == 1 && day <= 31)
if ( month == 3 && day <= 31)
if ( month == 5 && day <= 31)
if ( month == 7 && day <= 31)
if ( month == 8 && day <= 31)
if ( month == 10 && day <= 31)
if ( month == 12 && day <= 31)



bool daysInMonthIs31 = (month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8)
||(month == 10) || (month == 12);
bool daysInMonthIs30 = (month == 4) || (month == 6) || (month == 9) || (month == 11);

bool daysInFeb28 = (month == 2 && day <= 28);

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

string validDates;
if ( daysInMonthIs31) validDates = "This is a valid date";
else if ( daysInMonthIs30 ) validDates = "This is a valid date";
else if (daysInFeb28) validDates = "This is a valid date";
else if (ifLeapYear) validDates = "This is not a valid date";
else validDates = "This is not a valid date";





// output

cout << validDates << endl;

// Shutdown

// Pause/hold the screen
cout << endl;
cout << "Press ENTER to finish...";
cin.ignore(99,'\n');

// Return/Exit
return 0;
You are written much bad code,
why are you writing so many if condition..
try to combine it..
I am not sure how to combine them. I am new to the C++ so i am having trouble understanding.
if ( month == 4 && day <= 30)
if ( month == 6 && day <= 30)
if ( month == 9 && day <= 30)
if ( month == 11 && day <= 30)


can be combined as

if ((month == 4 || month == 6 || month == 9 || month == 11) && day <= 30)
ok thanks I got :)
Topic archived. No new replies allowed.