Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

127
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda