CodePudding user response:
If (input year for non integer)cout<" The Error "& lt;
While (1) {
Int ok=the scanf (" % d ", & amp; Year);
If (1!=ok | | year & lt; 1000 | | year & gt; 3000) {
Printf (" Error: must be greater than 1000 year is less than 3000, please input again \ n ");
The fflush (stdin);
}
}
CodePudding user response:
What input illegal means, the Numbers?Can use a regular, for example
STD: : regex e (" \ \ d {4} ");
STD: : string STR.
While (1) {
Printf (" do input year: ");
STD: : cin> STR;
Int ok=STD: : regex_match (STR, e);
If (ok) break;
Printf (" error, both please input again. ");
}
CodePudding user response:
If (y>=0 & amp; & (y %==0 400 | | (y % 4==0 & amp; & Y % 100!=0)))
This is a leap year judgment condition
The else
cout<" The error "
This is the meaning of
CodePudding user response:
1!=the scanf is determined, and required to enter an integer but enterthe condition of the floating point Numbers or lettersThe year behind the range is judged by effective range, for 3 years BC (3) is a leap year, when asked in 10000 is a leap year please
Common is 4, one hundred, 400 three judgments, and indeed in 3200, at the end of 172800 judgment?
The expression of the uncertainty, which is a leap year younger sister method you write