I began teaching myself programming 3 weeks ago. Its hard (for me) i'm trying to include some date validating within a program i am writing.

this is what i have so far, but invalid dates are validated unfortunately.
eg. November 31 2010
or february 30 2012

have a look and help me out please

#include <iostream.h>
#include <conio.h>


int main()
{

int day,dd,mm,yy,num;
char ans;
clrscr();

do{
cout<<"Enter Month: \n";
cin>> mm;

}while (mm<1||mm>12);

do{
cout<<"Enter Day: \n";
cin>> dd;

}while (dd<1||dd>31);

do{
cout<<"Enter Year: \n";
cin>> yy;
}while (yy<1||yy==num);



// validation

switch (mm){
case 1: if (1,3,5,7,8,10,12);
day=31;
break;
case 2: if (4,6,9,11);
day=30;
break;
case 3 :
if(((yy%4==0)&&(yy%100!=0))||(yy%400==0))
day=29;
else
day=28;

}

if (dd, mm, yy)
cout<<"The Date "<<mm<<'/'<<dd<<'/'<<yy<<" is VALID!"<<endl;
else
cout<< "The Date "<<mm<<'/'<<dd<<'/'<<yy<<" is INVALID!"<<endl;

do{
cout<<"do you want to try again?? (Y/N) "<<endl;
cin>>ans;
} while (ans!='n'&&ans!='N');


getch();

}

If you'd format your code I'd be happy to take a look at it. As it is, I'm not going to struggle with it.

i'm sorry, is this better ?

#include <iostream.h>
#include <conio.h>


int main()
{

	int day,dd,mm,yy,num;
	char ans;
	clrscr();

	do{
	cout<<"Enter Month: \n";
	cin>	> mm;

	}while (mm<1||mm>12);

	do{
		cout<<"Enter Day: \n";
		cin>> dd;

		}while (dd<1||dd>31);

	do{
		cout<<"Enter Year: \n";
		cin>> yy;

		}while (yy<1||yy==num);



// validation

switch (mm){
	case 1: if (1,3,5,7,8,10,12);
	day=31;
	break;

	case 2: if (4,6,9,11);
	day=30;
	break;

   case 3 :
	if(((yy%4==0)&&(yy%100!=0))||(yy%400==0))
	day=29;

   else
	day=28;

	}

	if (dd, mm, yy)
   	cout<<"The Date "<<mm<<'/'<<dd<<'/'<<yy<<" is VALID!"<<endl;
	else
		cout<< "The Date "<<mm<<'/'<<dd<<'/'<<yy<<" is INVALID!"<<endl;

do{
	cout<<"do you want to try again?? (Y/N) "<<endl;
	cin>>ans;
	} while (ans!='n'&&ans!='N');


getch();

}

i

ok, what i posted before was a little too difficult for a begginer like me.
I tried to a different way,

Here is my ORIGINAL UNCOMPLETE PROGRAM I AM ASSEMBLING SO FAR:

#include <iostream.h>

#include <conio.h>

void WeeklySales(); //we make weeklysales a function here too

main()
	{
   	int number;
      
      do
      	{      //displays the menu
         	cout << "******Sales System******";
            cout << ("\n\n");
      		cout << "1. Display Company Logo.\n"; endl;
      		cout << "2. Input/Validate weekly sales data.\n";endl;
      		cout << "3. Calculate weekly sales.\n";endl;
      		cout << "4. Display reciept.\n";endl;
      		cout << "5. SHUT DOWN & LOG OFF.\n";endl;
				cout << "\nEnter number...\n";endl;
         	cin >> number;
            cout << ("\n\n");
                  
      		switch (number)  //<--the expression is a variable (number) & controls the switch
            //the value of (number) is tested against a list of constants.
            //When a match is found, the statement sequence assosciated with that match is executed
               {
      				case 1:    //<-----  const = 1

            			cout << ("\n\tUU\tUU \tEEEEEEEE \tLL\t\t \SSSSSSS\n\tUU\tUU \tEE \t\tLL\t\tS\n\tUU\tUU \tEE \t\tLL\t\tS\n\tUU\tUU \tEEEEEEE \t\LL\t\t\ SSSSSS\n\tUU\tUU \tEE \t\tLL\t\t       S\n\tUU\tUU  \tEE  \t  \t\LL  \t\t       S \n\t UUUUUUUU   *\tEEEEEEEE  *\tLLLLLLL  *\tSSSSSSS   *\n\n\n\n\n");break;

            		case 2:   //<------const = 2. if match found, executes, then calls the weeklysales function below

            			cout << ("Weekly sales data\n\----------------- ");
                                WeeklySales();  //<-------------   function call here
                                break;

            		case 3:

            			cout << ("Calculate weekly sales "); break;

            		case 4:

            			cout << ("Display receipt "); break;

            		case 5:

            			cout << ("Goodbye, and thank you for using U.E.L.S. ");break;

                  //default statement sequence is executed if no matches are found
            		default:

            			cout << ("Enter a number from 1-5 only!");

         		}
      	} while (number !=5); //program will NOT stop looping till 5 is entered
      getch();
   }

void WeeklySales() //<--------weekly sales function not part of main() function
{                  //when function is completed, goes back to case 3:
//declare variables
	int salescode, bikeprice, modelcode, quantity, date;

   do
        //the instructions to enter the i.d. code will be repeated (do...while
        //loop) as long as the salescode is less than 1 or greater than 20.
   	{

      	cout << "\n\nPlease enter your identifiction code ";
         cin >> salescode;

         //the condition is tested
         if (salescode < 1 || salescode > 20)

         	{
            	cout << ("\nTHIS I.D. CODE IS NOT VALID. TRY AGAIN \n");
            }
      }
	//the instructions to enter the i.d. code will be repeated (do...while
   //loop) as long as the salescode is less than 1 or greater than 20.
   while (1 > salescode || salescode > 20);

   //another do...while loop
   do
   	{
      	cout << "\nPlease enter the bike price (one unit = 1 Euro) ";
      	cin >> bikeprice;

         if (bikeprice < 1 || bikeprice > 500)

         	{
            	cout << ("\nINVALID PRICE. Bike prices cannot be 0 or more than 500. TRY AGAIN \n");
            }
      }

   while (bikeprice < 1 || bikeprice > 500);

   //another do...while loop
   do
   	{
      	cout << "\nPlease enter the 3 digit model code ";
      	cin >> modelcode;

         if (modelcode < 0 || modelcode > 999)

         	{
            	cout << ("\nINVALID MODEL CODE. TRY AGAIN \n");
            }
      }

   while (modelcode < 0 || modelcode > 999);

   //another do...while loop
   do
   	{
         cout << ("\nPlease enter the quantity sold ");
      	cin >> quantity;

         if (quantity < 1 || quantity > 10)

         {
         	cout << ("\nINVALID QUANTITY. TRY A NUMBER FROM 1-10 \n");
         }
      }

   while (quantity < 1 || quantity > 10);

      	cout << "\nPlease enter the date ";
      	cin >> date;

        	cout << ("\n\n\n\n\n\n");
}

this program runs ok so far.
i want to add a date validation part to my program.

here is what i have so far

#include <iostream.h>

#include <conio.h>

main()

{

 		int date;

      char yes, no;

      yes = 'y';

      no = 'n';

      do {

     				cout << "\nPlease enter the date. eg. 020410 is 02/04/10 ";

               cin >> date;

               cout << "\nIs the the correct date ? press y/n \n" << date;

               cin >> yes || no;  //<------ i wasnt sure if this was correct

               if (char = no )

               		{

                        cout << ("\nPlease re-enter the correct date \n");
                        cin >> date;
                     }

           } while (char = yes);

          getch();

          }

how would i incorporate this into the original program ?
Please help!!!

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.