Iam after doing this program and it isnt working properly , it should give an output like

january 1, 1900
february 8, 1985// random number

january 1, 1900
may 25 , 1913 // random number

january 1, 1900
august 6 , 1912 // random number

#include <iostream>
using std::cout;
using std::endl;
#include <ctime>
#include <cstdlib>
enum Months { JAN = 1, FEB, MAR, APR, MAY, JUN,
              JUL, AUG, SEP, OCT, NOV, DEC };
void generateDate(int,int,int);
void printDate( enum Months, int,int);
bool validDate( enum Months ,int, int);
int getYear();
int getDay();
int getMonth(int);
int main()
{
   enum Months month = JAN;
   int day = 1;
   int year = 1900;
   srand( time( 0 ) );
   printDate( month, day, year );
   year = getYear();
   getMonth(month);
   day = getDay();
   if (validDate(month,day,year ) == true )
      printDate( month,day,year );
   
   return 0;
} // end main
// return month
int getMonth(int)
{
 int month_number = rand()% 12 + 1; 
   enum Months myMonth = (enum Months) month_number;
   return myMonth;
} // end getMonth
// return year
int getYear()
{
   return rand() % 101 + 1900;
} // end getYear
// return day
int getDay()
{ 
   return rand() % 31 + 1; 
} // end getDay
// output date
void printDate( enum Months, int day, int year )
{
  switch ( enum Months month = JAN ) {
 case JAN:
         cout << "January " << day << ", " << year << endl;
     
      case FEB:
         cout << "February " << day << ", " << year << endl;
         break;
      case MAR:
         cout << "March " << day << ", " << year << endl;
         break;
      case APR:
         cout << "April " << day << ", " << year << endl;
         break;
      case MAY:
         cout << "May " << day << ", " << year << endl;
         break;
      case JUN:
         cout << "June " << day << ", " << year << endl;
         break;
      case JUL:
         cout << "July " << day << ", " << year << endl;
         break;
      case AUG:
         cout << "August " << day << ", " << year << endl;
         break;
      case SEP:
         cout << "September " << day << ", " << year << endl;
         break;
      case OCT:
         cout << "October " << day << ", " << year << endl;
         break;
      case NOV:
         cout << "November " << day << ", " << year << endl;
         break;
      case DEC:
         cout << "December " << day << ", " << year << endl;
         break;
      default:
         cout << "invalid month\n";
   } // end switch
} // end printDate
// check for validDate
bool validDate(enum Months month, int day, int year )[B] I KNOW THIS LINE OF CODE IS[/B] wrong but it was the only way i could get it to work
{

   if ( year < 1900 || year > 2001 )
      return false;
   else if ( month < 1 || month > 12 )
      return false;
   else if ( day < 1 || day > 31 )
      return false;
   else if ( day == 31 && month == APR || month == JUN
             || month == SEP || month == NOV )
      return false;
   else if ( month == 2 && day > 28 )
      return false;
   else 
    return true;
} // end validDate

thanks

void printDate( enum Months, int day, int year )
{
  switch ( enum Months month = JAN )

I'm guessing what you really wanted here was:

void printDate( enum Months month, int day, int year )
{
  switch ( month )

Your random month isn't exactly ideal either. Is this supposed to be an exercise in enumerations or something?

No its actually a exercise on debugging .

Thanks for your .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.