+ 2

Quotations?

Do you need quotation marks around numbers when using the switch statement. For example: case ‘1’: or case “2”

13th Mar 2018, 10:35 PM
Peter Nguyen
Peter Nguyen - avatar
1 Respuesta
+ 9
If you're checking agaiast a string, use double quotes. Ex: case "Yes": case "yes": For char inputs, use single quotes. Ex: case 'Y': case 'y': case '1': //This checks for the character '1', not the number! For numbers (int, double, etc.), don't use quotes. case 1: By the way, welcome to the SoloLearn Q&A, Peter! ^_^ Here's our posting guidelines, if you're interested: https://www.sololearn.com/discuss/321242/?ref=app https://www.sololearn.com/Discuss/593497/?ref=app https://www.sololearn.com/Discuss/333866/?ref=app
13th Mar 2018, 10:43 PM
Tamra
Tamra - avatar