Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

128
Vistas
trying to create a switch with logical operators
#include <iostream>
#include <string>
using namespace std;

int main()
{
    int Hours;
    cout << "please enter number of hours worked";
    cin >> Hours;
    switch (Hours)
    {
    case 1: Hours == 40;
        cout << "worked full time this week";
        break;
    case 2:   Hours <= 30;
        cout << "You worked less than 40 this week available shifts on board";
        break;
    case 3: Hours > 30 && Hours < 40;
        cout << "You almost have 40 hrs check the board to see if shifts are available please do not go over 40 hrs";
        break;
    default: 
        cout << " invalid entry see you manager or try again";
    }



    {



    return 0;

}

I've done something wrong honestly do not really understand switch statements so just doing something pretty basic. I am getting a build error every time I try to run it. I want the user to input how many hrs worked and based on that display the message. I think an if/else statement would honestly be better but wanted to use a switch statement to get some practice.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

That's not the way you use switch

switch will take the value and compare it with all case. You can't do larger and less using switch.

You should use if-else instead:

if(Hours == 40)
{
    std::cout << "worked full time this week";
}
else if(Hours <= 30)
{
    std::cout << "You worked less than 40 this week available shifts on board";
}
else if(Hours > 30 && Hours < 40)
{
    std::cout << "You almost have 40 hrs check the board to see if shifts are available please do not go over 40 hrs";
}
else
{
    std::cout << " invalid entry see you manager or try again";
} 
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda