What data type can a case have? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 3

What data type can a case have?

When I was testing string around, I made a switch statement and declared that a case would be "Apple", but it resulted in an error; so can a case be a different data type than int?

14th Dec 2017, 11:46 PM
Harsit Baral
Harsit Baral - avatar
6 Antworten
+ 7
Yes, you can use string in switch, you can post your code, then we help you easier
14th Dec 2017, 11:58 PM
Vukan
Vukan - avatar
0
C++ doesn't support switches on arrays. http://en.cppreference.com/w/cpp/language/switch
15th Dec 2017, 12:06 AM
John Wells
John Wells - avatar
0
I am not good in math but I am doing my best on my own cheer me on. Love everyone. Who cares if I say this haha.😗
15th Dec 2017, 3:36 AM
Felicia Law
Felicia Law - avatar
0
https://code.sololearn.com/cKB9qG2oSNCC/?ref=app You can use string in switch . In the above code I used character in switch just check if it helps .
15th Dec 2017, 3:48 AM
Hrishikesh Kulkarni
Hrishikesh Kulkarni - avatar
0
You can use a enum in switch, and the compiler tell you if one enum is not defined in your switch. Example: enum probe {one, two, three}; switch (enum probe) { case one: case two: case three: } Its a very simple example. I hope to help you.
15th Dec 2017, 4:03 AM
Iago
Iago - avatar
- 1
@Felicia I am sorry about your math skills and I care that you said it. However, your post has nothing to do with this question so needs to be deleted. Please avoid off topic posts in the future. https://www.sololearn.com/Discuss/321242/?ref=app
15th Dec 2017, 3:43 AM
John Wells
John Wells - avatar