0

How will I properly run my swtch case?

I am having problems compiling it. it usually says that it expects a ";" before a ":". Help me fix the error please.

31st Dec 2016, 5:01 PM
Jerome Lester V. (thunderlocus3)
Jerome Lester V. (thunderlocus3) - avatar
6 odpowiedzi
+ 3
you should also use break; statement after every case
31st Dec 2016, 8:51 PM
Yash Jain
Yash Jain - avatar
+ 2
Try this switch (l) { case 'M': cout<<"string of text"<<endl; case 'F': cout<<"another string of text" <<endl; case 'm': cout<<"string of text"<<endl; case 'f': cout<<"another string of text" <<endl; default: cout<<"my default case"; cin>>l; }
31st Dec 2016, 8:50 PM
Yash Jain
Yash Jain - avatar
+ 1
must be using unnecessary colon or semicolon......send the switch case code you wrote
31st Dec 2016, 5:14 PM
Dhairya Karna
Dhairya Karna - avatar
0
switch (l) { case 'M','m': cout<<\*string of text*\<<endl; case 'F','f': cout<<\*another string of text*\ <<endl; default: cout<<\*my default case*\; cin>>l; }
31st Dec 2016, 5:18 PM
Jerome Lester V. (thunderlocus3)
Jerome Lester V. (thunderlocus3) - avatar
0
First. You can't separate conditions by a comma. You can write as case 'M': case 'm': Second. for comments these are wrong slash..... use normal slash(/) rather than backward slash(\) Third. In the cout line the compiler skips the comments after correction so the compiler may read it as cout<< <<endl; which will display an error as there is no need for two <<....
31st Dec 2016, 5:35 PM
Dhairya Karna
Dhairya Karna - avatar
0
I just did the comments for my strings. So I need to do it like a case per char?
31st Dec 2016, 5:37 PM
Jerome Lester V. (thunderlocus3)
Jerome Lester V. (thunderlocus3) - avatar