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

126
Views
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 answers
Answer question

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 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!