Week end / business day program help

Hi guys,I'm fairly new in C++ (3rd day) and I'm trying to apply the enum operator. So I tried to write a program that determines whether the user indicated (via cin) a weekend or a business day (week day). The problem is the program cannot determine if its a weekend. How can I make this program work?

Thanks in advance!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
using namespace std;
int main()
{
   enum DAYS (Monday, Teusday, Wednesday, Thursday, Friday, Saturday, Sunday)
   unsigned short int today;
   cin >> today;
   if (today == Saturday || today == Sunday)  
        cout << "Weekend!!!";                 
   else
        cout << "Business day!!!";
   return 0;
}
Last edited on
closed account (1vRz3TCk)
Your enumeration is wrong:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;
int main()
{
   enum DAYS {Monday=1, Teusday, Wednesday, Thursday, Friday, Saturday, Sunday};
   unsigned short int today;
   cin >> today;
   if (today == Saturday || today == Sunday)  
        cout << "Weekend!!!";                 
   else
        cout << "Business day!!!";
   return 0;
}

Thanks, btw, do you have any suggestions on how the code can determine if its a weekend or week day/business day? thanks
closed account (1vRz3TCk)
As it is (as long as the input is between 1 and 7 inclusive) it should work.

but you could do something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
int main()
{
   enum DAYS {Monday=1, Teusday, Wednesday, Thursday, Friday, Saturday, Sunday};
   unsigned short int today;
   cin >> today;
   switch(today)
   { 
       case Monday ... Friday:
            cout << "Business day!!!";
            break;
        case Saturday ... Sunday:
            cout << "Weekend!!!";
            break;
        default:
            cout << "Not a valid day!";
            break;
   }
   
   return 0;
}


or do a case fall through
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
case Monday:
case Teusday:
case Wednesday:
case Thursday:
case Friday:
    cout << "Business day!!!";
    break;
case Saturday: 
case Sunday:
    cout << "Weekend!!!";
    break;
default:
    cout << "Not a valid day!";
    break;
Last edited on
Thanks for the help, I appreciate it very much.
Topic archived. No new replies allowed.