
Federico Moreno
PreguntaHola, comparto algo que descubrí por ahí. Es para poner un rango entre 2 números en un
case
#include <iostream> using namespace std; int main() { int math = 0; int biology = 0; cout << "What grade did you get in math? "; cin >> math; /* // Switch statement with range "..." switch (math) { case 10: cout << "You're a genious." << endl; break; case 7 ... 9: cout << "You passed the math exam! Congrats!" << endl; break; default: cout << "You failed in math! We need to evaluate you again!" << endl; } return 0; } */ // Switch statement with a lot of cases to one output. switch (math) { case 10: cout << "You're a genious." << endl; break; case 7: case 8: case 9: cout << "You passed the math exam! Congrats!" << endl; break; default: cout << "You failed in math! We need to evaluate you again!" << endl; } return 0; }

Ernán Alexander Velásquez Ramírez
Gracias! Lo usé en este código:
#include <iostream> using namespace std; int main() { int mathScore = 0, biologyScore = 0; cout << "¿Cuánto sacaste en matemáticas?" << endl; cin >> mathScore; cout << "¿Cuánto sacaste en biología?" << endl; cin >> biologyScore; switch (mathScore) { case 10: cout << "Eres un puto genio en matemáticas" << endl; break; case 7 ... 9: cout << "Muy buen trabajo en matemáticas" << endl; break; default: cout << "Necesitas trabajar más en matemáticas" << endl; break; } switch (biologyScore) { case 10: cout << "Eres un puto genio en biología" << endl; break; case 7 ... 9: cout << "Muy buen trabajo en biología" << endl; break; default: cout << "Necesitas trabajar más en biología" << endl; break; } return 0; }

Federico Moreno
Bueno, creo que sería interesante en el caso de que coincida con 7, 8 y 9 (en el que se devuelve el mismo resultado). Hay dos formas:
case 7: case 8: case 9: cout << ¡Aprobaste! << endl;
case 7 ... 9: cout << ¡Aprobaste! << endl;
switch
if

Erika Luna
woow, qué caso de uso les ves?