Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
Cambiar declaración con valor entero

Soy nuevo en C ++ y estoy atascado en la declaración de cambio porque no parece dar una salida cuando el valor entre paréntesis es un número entero (Console-Program terminó con el código de salida: 0). Aunque, el mismo código funciona bien cuando cambio el tipo a char. Gracias.

 int main() { int num1; // argument of switch statement must be a char or int or enum cout<< "enter either 0 or 1" << "\n"; cin>> num1; switch (num1) { case '0': cout<< "you entered 0" << endl << endl; break; case '1': cout<< "you entered 1" << endl << endl; break; } }
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Está activando un int , lo cual es correcto, pero sus casos no son números enteros, son char ya que están rodeados por ' .

'0' nunca es igual a 0, ni '1' nunca es igual a 1.

Cambie los valores de mayúsculas y minúsculas a números enteros.

 int main() { int num1; cout<< "enter either 0 or 1" << "\n"; cin>> num1; switch (num1) { case 0: cout<< "you entered 0" << endl << endl; break; case 1: cout<< "you entered 1" << endl << endl; break; } }
over 4 years ago · Santiago Trujillo Report

0

int main() { int num1; // argument of switch statement must be a char or int or enum cout<< "enter either 0 or 1" << "\n"; cin>> num1; switch (num1) { case 0: cout<< "you entered 0" << endl << endl; break; case 1: cout<< "you entered 1" << endl << endl; break; } }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!