You have two problems:
1. Add a break statement after you set i to zero:
void validate_name(string &name)//validate_name for each student
{
int i;
for(i=0;i<(name.length());i++)
{
while( !(isalpha(name[i])) && !(isspace(name[i])) )
{
cout<<"Enter correct Name of student ,please:\n";
getline(cin,name);
i=0;
break;
}
}
}
2. You need to get that last newline you left in the buffer after getting the year.
...
cin>>d>>m>>y;
cin.ignore( 10000, '\n' );
...
The trouble happens because you are mixing >> with getline().
Hope this helps.
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
If you want to know, take out the break and try the following input:
Enter name,please:
0123
Enter the date 1 1 2007
Enter correct name of student, please 9jake
Also:Enter name,please:
no2
Enter the date 1 1 2007
Enter correct name of student, please m
The 10000 means to read a maximum of 10,000 characters. It is just some really big number that is sure to be larger than any line of text the user input after "2007" but before hitting ENTER.
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
i take out break and i try your input the code is work and
when i leave it ,the code did not work ??????????
Yes, that's the whole point.
Get a piece of paper and a pencil and draw yourself what is happening when you use the code without thebreak statement, and you will see why it doesn't work.
Good luck.
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
Hmm, you know, you are absolutely right. I must have been really tired when I did that. Yes, leave the break statement out. (Or, leave it in and set i=-1 .)
Good job.
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229