Home > Back-end >  O solve the problem of cin&switch statement in c
O solve the problem of cin&switch statement in c

Time:09-15

Char I; Cin> i;
While (getchar ()! )
='\ n'The continue;
The switch (I)
{
Case '1' :
Excourse. CourseInfoInput ();
System (" pause ");
Break;
Case '2' :
Excourse. CourseSelective ();
System (" pause ");
Break;
Case '3' :
Excourse. CourseInfoOutPut ();
System (" pause ");
Break;
Case '4' :
Excourse. The Search ();
System (" pause ");
Break;
Case '5' :
Excourse. CourseSelection_Statistics ();
Break;
Case '0' :
The exit (0);
Default:
Cout<& lt;" \ n input error please re-enter "& lt; Break;
}
12 is executed in the program input 1, the result of the use to the cin I only 1 copy this results cannot be saved 2 how to solve this problem, the result o

CodePudding user response:

The
refer to the original poster qq_31050793 response:
char I; Cin> i;
While (getchar ()! )
='\ n'The continue;
The switch (I)
{
Case '1' :
Excourse. CourseInfoInput ();
System (" pause ");
break;
Case '2' :
Excourse. CourseSelective ();
System (" pause ");
break;
Case '3' :
Excourse. CourseInfoOutPut ();
System (" pause ");
break;
Case '4' :
Excourse. The Search ();
System (" pause ");
break;
Case '5' :
Excourse. CourseSelection_Statistics ();
break;
Case '0' :
The exit (0);
Default:
Cout<& lt;" \ n input error please re-enter "& lt; break;
}
12 is executed in the program input 1, the result of the use to the cin I only 1 copy this results cannot be saved 2 how to solve this problem, the result o

You get rid of break case '1' is ok, but as long as meet the characters' 1 ', the two case will be executed
  • Related