Case
The switch case statement is occasionally used in programming, and there are two errors in the handling of case statements, which are summarized as follows:
1 case must be constant, cannot use ' < ' or ' > ' This logical operation after 2 case if ' | | ' or ' && ' logical operation, then the actual is 1 or 0#include <iostream>using namespace std;int main (int argc, char * argv[]) { int i;< c1/>cin>>i; switch (i) {case : cout<<i<<endl; break; Case ' a ': cout<<i<<endl; break; Default: cout<< "Hello" <<endl; } return 0;}
If
There are two main errors that can occur during programming using the IF process:
1Determine logical errors, such as if (i=0)2 ifElseIf ElseIf only executes one if or one does not perform # include<iostream>using namespacestd;intMainintargcChar*argv[]) { inti; CIN>>i; if(i==1) cout<<i<<Endl; Else if(i>0) cout<<i+1<<Endl; Else if(i==0) cout<<i<<Endl; return 0;}
Switch case and if