0
Where is the mistake
#include <iostream> using namespace std; int main() { string age; cin>>age; switch (age) { case "ABC": cout << "2000"; break; case "اDEF": cout << "1997"; break; case "GHI": cout << "1996"; break; return 0; }
5 Réponses
+ 4
You're missing closing curly brace (}) of the body of a switch statement.
C++ Switch Statements
Use the switch statement to select one of many code blocks to be executed.
https://www.w3schools.com/cpp/cpp_switch.asp
This is how it works:
The switch expression is evaluated once
The value of the expression is compared with the values of each case
If there is a match, the associated block of code is executed
The break and default keywords are optional
+ 1
// Hope this link helps you
https://stackoverflow.com/questions/16388510/evaluate-a-string-with-a-switch-in-c
+ 1
Does this mean that the switch does not work with the string?
+ 1
Ramadan, that's right.
C++ switch statement cannot accept string as evaluation subject.
However we can create our own function to achieve somewhat similar result.
https://code.sololearn.com/cCqd6prmLX9M/?ref=app
0
No, there is another error