title: C++ validating date without using class
body: <p>Hi I am hoping someone can help me out with what I am doing wrong.  This is homework I will point out but was in need of someone to tell me what a moron I am because I am not seeing what it is that I am doing wrong.</p>
  
  <p>I am supposed to let the user enter a month, day, and year to determine if it is a magic date.  That part I had already done for another project. I am supposed to go back and validate the date using a function named isDateValid. I'm pretty sure I am missing something obvious and could use anyones help on the subject.  Thanks!</p>
  
  <p>The problem is when I run it I am always getting that it is an invalid date!</p>
  
  <pre><code> #include &lt;iostream&gt;
   using namespace std;
  
   bool leapYear(int);
   bool isDateValid(int, int, int);
  
   int main()
   {
   int month, day, year;
  
   cout &lt;&lt; "Is the date you are thinking of a magic one? Let's see...\n";
   cout &lt;&lt; "What is the month in numeric form only? "; cin &gt;&gt; month;
   cout &lt;&lt; "What is the day of the month? "; cin &gt;&gt; day;
   cout &lt;&lt; "What is the four digit year? "; cin &gt;&gt; year;
  
   if (isDateValid(month, day, year) == false)
   {
   cout &lt;&lt; "The date you entered, "&lt;&lt; month &lt;&lt; "/" &lt;&lt; day &lt;&lt; "/" &lt;&lt; 
   year &lt;&lt; " is NOT a VALID Date.\n";
   cout &lt;&lt; "If you think I am wrong, please feel free to run me again";
   }
  
   else   if (month * day == year % 100) // if true then do this
   {
   cout &lt;&lt; "The date you entered, " &lt;&lt; 
   month &lt;&lt; "/" &lt;&lt; day &lt;&lt; "/" &lt;&lt; year &lt;&lt; " is a magic date!!\n"; 
   }
   else // if false then do this
   {
   cout &lt;&lt; "The date you entered, " &lt;&lt; month &lt;&lt; "/" &lt;&lt; day &lt;&lt; "/" &lt;&lt;
   year &lt;&lt; " is NOT a magic date!!\n";
   }
  
                                                              //Program ID
   cout &lt;&lt;"\n" &lt;&lt; "L5P1LB.cpp\n" &lt;&lt; "11-26-12\n" &lt;&lt; endl;
   system ("pause");
   return 0;
   }//end main
  
   // isDateValid function to validate date entered
   bool isDateValid(int month, int day, int year)
   {
   bool validation = true;
   if(!(year &gt;= 1600 &amp;&amp; year &lt;=2100))
       validation = false;    
   if(leapYear(year))
   {
       if ((month == 2) &amp;&amp; (day &gt; 29))
           validation = false;
       }
   else if(!leapYear(year))
   {
        if ((month == 2) &amp;&amp; (day &gt; 28))
            validation = false;
            }    
   if((month &lt; 1 &amp;&amp; month &gt; 12) || (day &lt; 1))
       validation = false;
   if((month == 1) || (month ==3) || (month == 5) || (month == 7) ||
       (month == 8) || (month == 10) || (month == 12) &amp;&amp; (day &gt; 31))
       validation = false;
   else if (((month == 4) || (month == 6) || (month == 9) || (month == 11)) &amp;&amp; 
        (day &gt; 30))
        validation = false;
   else
        validation == true;
   return validation;
   }
   // leapYear function to determine if the year is a leap year for validation
   bool leapYear(int year)
   {
   return(year % 100 != 0 &amp;&amp; year % 4 == 0) || (year % 400 == 0);
   } // end leapYear
  </code></pre>
  
  <p>EDIT</p>
  
  <p>Okay now my problem is that I am not getting that it is NOT A valid date when it is.  Its skipping the validation all together and just running the "magic date" part of it!</p>
  
  <p>Here's the rewrite plus my full code hopefully indented here properly as it is in Bloodshed.</p>
  
  <pre><code>Description: This program determines if when the user enters a month, 
  day, and four digit year which will then be stripped down to its
  two digit year and determined to be a magic date if the day entered 
  multiplied by the month entered equals the years two digit format.
  Design:
      begin main
          input data
              Ask user for a month in number form
              Ask user for a day of the month
              Ask user for four digit month
          Validate
              begin isDateValid
                  if year is between 1600 and 2100, inclusive then return 
                      true
                  if month is between 1 and 12, inclusive return true
                  if month is Jan, Mar, May, July, Aug, Oct, Dec 
                     then if day is between 1 and 31 inclusive return true
                  if month is Apr, June, Sept, Nov
                     then if day is between 1 and 30 inclusive return true
                  if month is Feb
                     then determine if leap year by running function 
                     leapYear provided for us.
                     if leap year is true 
                     then if day is between 1 and 29, inclusive return true
                     if not leap year then if day is between 1 and 28, 
                     inclusive then return true
              end isDateValid
          if isDateValid is true then 
          Calculate
              if the month times the year is equal to the year modulus 100
              then output it is a magic date
              if it does not equal the year in 2 digit form
              then output that it is not a magic date    
          else output error message
  
          Output Program ID
      end main
  
      The output needs to include the books data of 6/10/1960 */
  #include &lt;iostream&gt;
  using namespace std;
  
  bool leapYear(int);
  bool isDateValid(int, int, int);
  
  int main()
  {
      int month, day, year;
  
      cout &lt;&lt; "Is the date you are thinking of a magic one? Let's see...\n";
      cout &lt;&lt; "What is the month in numeric form only? "; cin &gt;&gt; month;
      cout &lt;&lt; "What is the day of the month? "; cin &gt;&gt; day;
      cout &lt;&lt; "What is the four digit year? "; cin &gt;&gt; year;
  
  if (isDateValid(month, day, year) == false)
  {
      cout &lt;&lt; "The date you entered, "&lt;&lt; month &lt;&lt; "/" &lt;&lt; day &lt;&lt; "/" &lt;&lt; 
           year &lt;&lt; " is NOT a VALID Date.\n";
      cout &lt;&lt; "If you think I am wrong, please feel free to run me again";
  }
  
  else  if (month * day == year % 100) // if true then do this
  {
      cout &lt;&lt; "The date you entered, " &lt;&lt; 
           month &lt;&lt; "/" &lt;&lt; day &lt;&lt; "/" &lt;&lt; year &lt;&lt; " is a magic date!!\n"; 
  }
  else // if false then do this
  {
      cout &lt;&lt; "The date you entered, " &lt;&lt; month &lt;&lt; "/" &lt;&lt; day &lt;&lt; "/" &lt;&lt;
           year &lt;&lt; " is NOT a magic date!!\n";
  }
  
                                                              //Program ID
  cout &lt;&lt;"\n" &lt;&lt; "L5P1LB.cpp\n" &lt;&lt; "11-26-12\n" &lt;&lt; endl;
  system ("pause");
  return 0;
  } //end main
  
  // isDateValid function to validate date entered
  bool isDateValid(int month, int day, int year)
  {
      bool validation = true;  // validation set to true
      // if it is not between 1600 and 2100 then set to false
      if(!(year &gt;= 1600 &amp;&amp; year &lt;=2100))
          validation = false;
      // call leapYear function
      if(leapYear(year))
  {
      // if February and day is greater than 29 then set to false
      if ((month == 2) &amp;&amp; (day &gt; 29))
           validation = false;
  }
      // else if NOT leapYear
      else if(!leapYear(year))
  {
      // if February and day is greater then 28 then set to false
      if ((month == 2) &amp;&amp; (day &gt; 28))
            validation = false;
  }    
      // if month is less then 1 and over 12 then set to false
      if((month &lt; 1 &amp;&amp; month &gt; 12))
            validation = false;
      // if day is less then 1 then set to false    
      if(day &lt; 1)    
            validation = false;
      // if month is 1 (Jan), 3 (Mar), 5 (May), 7 (July), 8 (Aug), 10 (Oct),
      // or 12 (Dec) and day is greater then 31 set to false    
      if((month == 1) || (month ==3) || (month == 5) || (month == 7) ||
           (month == 8) || (month == 10) || (month == 12) &amp;&amp; (day &gt; 31))
           validation = false;
      // if month is 4 (Apr), 6 (June), 9 (Sept), or 11 (Nov) and day is 
      // greater then 30 set to false
      if (((month == 4) || (month == 6) || (month == 9) || (month == 11)) &amp;&amp; 
           (day &gt; 30))
           validation = false;
      // else everything that is left set validation to true
      else
           validation = true;
  return validation;
  }  // End isDateValid
  
  // leapYear function to determine if the year is a leap year for validation
  bool leapYear(int year)
  {
      return(year % 100 != 0 &amp;&amp; year % 4 == 0) || (year % 400 == 0);
  } // end leapYear
  </code></pre>
  
  <p>Sorry if I put in the wrong spot or anything!</p>
  
  <p>Thanks for your help also.  It is truly appreciated.</p>