DATE VALIDATOR..fixin errors

can you please help me with my code?
cant run it..there's some errors...
please help me..thanks..

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

int main()
{

char ans,Y;
int dd,mm,yy;

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

}while (dd=30);

do<
cout<<"Enter Month: \n";
cin>> mm;
}while (mm=12);

do<
cout<<"Enter Year: \n";
cin>> yy;
}while (yy=0);

// validation

switch (mm){
case 1,3,5,7,8,10,12 ; days=31
break;
case 4,6,9,11 ; days=30;
break;
case 2 ; if (yy%%4=0)days=29;
else
days=28;
}

if (dd from 1 to days)
cout<<"valid";
else
cout<< "invalid";

getch();

return0;
}
do< //this should be {
cout<<"Enter Date: \n";
cin>> dd;

}while (dd=30); //this code here will set dd to 30 every time it is evaluated,
//hence while condition is really while(dd), so since dd is 30 every time the
//loop runs forever
//correct usage for loop evaluation is '==' which test for equality
// '=' operator always makes an assignment. The same applies for all your
//do while loops

switch (mm){
case 1,3,5,7,8,10,12 ; days=31
break;
case 4,6,9,11 ; days=30;
break;
case 2 ; if (yy%%4=0)days=29;//same mistake here using '='
else
days=28;
}//this switch block uses invalid syntax. First to have the same statement
//evaluated for multiple conditions the syntax is this:
// case <condition>: case <condition>: case <condition: //etc.
//also note case selectors are delimited by colons not semicolons
//here is correct code
switch (mm){
case 1: case 2: case 3: case 5: case 7: case 8: case 10: case 12:
days=31;
break;
case 4: case 6: case 9: case 11: days=30;
break;
case 2: if (yy%4==0)days=29;
else
days=28;
}



if (dd from 1 to days)
//I think I now what you meant by this but this is definitly NOT
//a C++ statement
//to test is days is between 1 and days inclusive, this test will work

if (dd >= 1 && dd <= days) cout << "valid";
//this says if dd is greater than or equal to 1 and dd is less than or equal
//days then output valid, if not output invalid

days=28; //this variable is not defined you must define it as int,double,float
//but since it only holds integers it should be an integer. That should fix
//the undefined error problem
hi thanks for your help... now i got it right... my program runs very ok...
but the last part is not yet ok... about the "do you want to try again?" i want to return it to the start so that can able to try the program again... my code is not working can you help me to fix it? tnx...





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

//Main Function

int main()
{

int days,month,dd,mm,yy,num;
char ans,again;

do{
cout<<"Im Data Validator!Wanna Try me?! (Y/N) \n";
cin>>ans;
}while(ans=='N'||ans=='n');

do{
cout<<"Enter Date: \n";
cin>> dd;
}while (dd==1&&dd==31);

do{
cout<<"Enter Month: \n";
cin>> mm;
}while (mm==1&&mm==12);

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


// Function

switch (mm){
case 1: case 3: case 5: case 7:case 8: case 10: case 12 : days=31;
break;
case 4: case 6: case9: case 11 : days=30;
break;
case 2 : if (yy%4==0)days=29;
else
days=28;
}

// Function

if (dd>=1&&dd<=days&&mm>=1&&mm<=month)
cout<<"Your Date is Valid!! \n";
else
cout<< "Sorry Your Date is Invalid \n";

do{
cout<<"Do you want to try it again? (Y/N)";
cin>>again;

}while (again=='N'||again=='n');


getch();

return 0;

}
Topic archived. No new replies allowed.