+ 1
What is the error of this code?
#include <iostream> using namespace std; int main() { int age=42 ; switch (age) { case:16 cout << "so yung"; break ; case:42 cout << "Adult"; break; case:70; cout << "oldman"; break ; } return 0; }
9 Answers
+ 2
Mhi tj the switch/case statement only checks for specific ages. It does not check for age ranges between the given numbers. To check for age ranges instead, use if/else.
if (age<=16)
cout << "so young";
else if (age<=42)
cout << "Adult";
else if (age<=70)
cout << "Middle-aged";
else
cout << "Old man";
+ 2
Semicolon error in case 3rd
+ 1
Tnxđ„șđ„Č
+ 1
Brian I just wanted to learn how to write code with a switch. Please tell me the uses of the switch, thank you
+ 1
Ok tnx FF990đđ
+ 1
switch (itemState) {
case "working" :
readyUnits++;
break;
case "uncalibrated" :
item.calibrateFunction();
break;
case "broken" :
removeFromInventory();
case "damaged" :
if (canBeRepaired) {
repairWorkshop.add(item);
} else {
removeFromInventory();
}
stripForParts(); // strips broken and !canBeRepaired
+ 1
int initialAggression = 2;
int rudimentaryAI = initialAggression + currentAggression + diceRoll(numberOfDice: 1);
void makeAImoreAggressive() {
currentAggression++;
}
void makeAImoreAfraid() {
initalAggression--;
}
switch (rudimentaryAI) {
case 0 :
case 1 :
case 2 :
case 3 :
case 4 :
case 5 :
case 6 :
computerPlayer.Retreat();
break;
case 7 :
case 8 :
case 9 :
case 10 :
case 11 :
computerPlayer.Advance();
break;
default :
computerPlayer.Fire(); // anything higher than 11 or lower than 0