#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.
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";
}