Home > Back-end >  C beginners help great god c program logic problem?
C beginners help great god c program logic problem?

Time:11-13

I self-study c + +, programming in the eyes, but encountered a problem, I think the program do not have what problem can is wrong:
Void Student_Msg: : InputData ()
{
Int p;
Char s [41];
cout <"Please enter the student information (NO" & lt; cout <"Name:";
Cin & gt;> s;
Name=new char (strlen (s) + 1);
Strcpy (name, s);
cout <"Gender (1) male, 0. Female) :";
Cin & gt;> p;
If (p)
Sex=true;
The else
Sex=false;
cin & gt;> The date;
cout return;
}
Cin & gt;> The date is a class object, will call & gt;> Operator overloading function:
Cost & amp; The operator & gt;> (cost & amp; In the CDate & amp; D)
{
Char ch1 and ch2.
cout <"Please enter the date (input format: yyyy - mm - dd) :";
While (1)
{
Cin & gt;> D.y ear & gt;> Ch1 & gt;> D.m onth & gt;> Ch2 & gt;> D.d ay;
If (ch1=='-' & amp; & Ch2=='-')
{
cout <"Time format correct" & lt; break;
}
The else
{
cout <"Time format is not correct, please input again" "& lt; break;
}
}
Return cin
}
The main function is cycle detection:
while(! End)
{
cout For (I=0; i <6; I++)
{
cout }
Cin & gt;> The input;
The switch (input)
{
Case 0:
Student_Msg: : num++;
Stu [Student_Msg: : num] InputData ();
break;
}
}
Now the question is: if the input of time, the main program blocks to the cin & gt;> The input; Waiting for user input again, and if the input error time problems arise:
Will always circulation print: "time format is not correct, please input again" does not block the cin & gt;> Input waiting for user input,
This is I have been think impassability, I think no problem, and input the right time, input the wrong time to deal with is the same:
If (ch1=='-' & amp; & Ch2=='-')
{
cout <"Time format correct" & lt; break;
}
The else
{
cout <"Time format is not correct, please input again" "& lt; break;
}
}
Return cin
Why the blocks of time, no wrong time blocking has been circulating print? A great god taught c + +,
  • Related