dateType::dateType()
{
day = 0;
month = 0;
year = 0;
}
void dateType::setdate()
{
cout<<"Set Date-of-Birth"<<endl<<endl;
int d = 0, m = 0, y = 0;
do
{
cout<<"Enter Day : ";
cin>>day;
if(day >= 1 && day <= 31)
d = 1;
else
cout<<"Enter Day Between 1-30 "<<endl;
}while (d != 1);
do
{
cout<<"Enter Month : ";
cin>>month;
if(month >= 1 && month <= 12)
m = 1;
else
cout<<"Enter Month Between 1-12 "<<endl;
}while (m != 1);
do
{
cout<<"Enter Year : ";
cin>>year;
if(year >= 1960 && year <= 2000)
y = 1;
else
cout<<"Enter Year Between 1960-2000 "<<endl;
}while (y != 1);
}
int main()
{
string serchname;
int n;
addressBookType adbook[SIZE];
/////////////////-------------->>>>>>>>> INPUT
cout<<endl<<endl<<" *** Enter Data ***"<<endl<<endl
<<"Enter Number of entries do you want to Enter : ";
cin>>n;
for (int i=0;i<n;i++)
{
cout<<"Enter entry No. "<<i+1<<endl<<endl<<endl;
adbook[i].setd();
cout<<endl<<endl<<endl;
}
system("pasue");
system("CLS");
cout<<endl<<endl<<"***** Data Entry Completed *****"<<endl;
system ("pasue");
system ("CLS");
for(int i=5; i>0;i--)
{
cout<<endl<<endl<<endl<<endl<<" Your Program Will Close in " <<i<<" sec ."<<endl;
Sleep(400);
system("CLS");
cout<<endl<<endl<<endl<<endl<<" Your Program Will Close in " <<i<<" sec .."<<endl;
Sleep(400);
system("CLS");
cout<<endl<<endl<<endl<<endl<<" Your Program Will Close in " <<i<<" sec ...";
Sleep(400);
system("CLS");
}
I can strongly recommend this way because it's very easy to use correctly and it also has the following advantages compared to using cin.ignore():
– If the user press enter before inputting anything it will keep waiting for input just like using the >> operator would.
– There is no problem if the user has inputted additional whitespace characters on the previous input line.
– Any whitespace characters at the beginning of the line are ignored and will not be part of the string.