I'm having an issue with a program that prompts a user for a date and then validates it. It requires a switch statement to validate the day and at least 2 Boolean variables. My problem is with either of those or possibly both. I'm honestly guessing both since I'm still a little new at this... this is the 5th time I've rewritten this and I have no idea what to try at this point.

#include <iostream>
using namespace std;

main()
{
int month, day, year;
bool daycheck = false;
bool leap = false;

    cout << "Please enter a date (MM DD YYYY):" << endl;
    cin >> month >> day >> year;
    
    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    
    if (year % 4 == 0)
       leap == true;
       
           
    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx       
           
    switch (month)
    {
           case 1:
           case 3:
           case 5:                
           case 7:
           case 8:
           case 10:
           case 12:
                      
                if ((day >= 01) && (day <= 31))
                   daycheck == true; 
                   break;
                   
           case 4:
           case 6:
           case 9:
           case 11:   
                
                if ((day >= 01) && (day <= 30))
                   daycheck == true;
                   break;
                   
           case 2:
                
                      if (leap = true)
                         {
                              if ((day >= 01) && (day <= 29))
                                 daycheck == true;
                         
                         }
                         else if ((day >= 01) && (day <= 28))
                           daycheck == true;
                           break;
          
    }            
                     
    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    
    if (daycheck = false)
       cout << "Invalid day of the month: " << day << endl;
    if ((month >= 13) || (month <= 0))
       cout << "Invalid Month: " << month << endl;
    if ((year <= 1901) && (year >= 2010))
       cout << "Invalid Year:  " << year << endl;  
    if ((month <= 12) && (month >= 1) && (daycheck = true) && (year >= 1901) && (year <= 2010))
       cout << month << "/" << day << "/" << year << " is a valid date" << endl;
                      

system("pause");
return 0;
}

i originally had Boolean checks for month and year but since i couldn't get those to work either i ditched them for the much simpler if statement

Edited 7 Years Ago by valkerye: n/a

You are confusing the assignment operator = and the boolean operator ==.

line 46: use == operator, not the = operator. Similar problem in other lines of code at lines 60-69. if (leap == true) lines 32, 41,49, and 53: use = assignment operator, not == boolean operator.

Edited 7 Years Ago by Ancient Dragon: n/a

This question has already been answered. Start a new discussion instead.