C++ Code Example: get weekday

The following switch-case statement returns the appropriate day of the week based on a number.

#include <iostream>
using namespace std;

string getWeekDay(int num) {
    switch (num) {
        case 1:
            return "Monday";
            break;
        case 2:
            return "Tuesday";
            break;
        case 3:
            return "Wednesday";
            break;
        case 4:
            return "Thursday";
            break;
        case 5:
            return "Friday";
            break;
        case 6:
            return "Saturday";
            break;
        case 7:
            return "Sunday";
            break;
        default:
            return "no valid value";
    }
}

int main() {
    int num = 3;
    cout << "Weekday of number 3 is: " << getWeekDay(num) << endl;
}
Output
Weekday of number 3 is: Wednesday