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; }

24th May 2022, 12:10 AM
RAMADAN : رمضان
RAMADAN : رمضان - avatar
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
24th May 2022, 12:38 AM
SoloProg
SoloProg - avatar
24th May 2022, 2:23 AM
SoloProg
SoloProg - avatar
+ 1
Does this mean that the switch does not work with the string?
24th May 2022, 3:02 AM
RAMADAN : رمضان
RAMADAN : رمضان - avatar
+ 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
24th May 2022, 5:43 AM
Ipang
0
No, there is another error
24th May 2022, 2:13 AM
RAMADAN : رمضان
RAMADAN : رمضان - avatar