xFactorSchool.com(Beta)
How to Do Examples
Python Examples
HTML Examples
Code Examples
C Code Examples
C++ Code Examples
C# Code Examples
Java Code Examples
Python Code Examples
HTML Code Examples
CSS Code Examples
JavaScript Code Examples
Online Editor
C Code Editor
C++ Code Editor
C# Code Editor
Java Code Editor
Python Code Editor
HTML Code Editor
CSS Code Editor
JavaScript Code Editor
Practice how to use switch in C++
C++ Online Editor
Execute Code
More C++ Sample Code
#include <iostream> #include <ctime> // for time related operations using namespace std; // use std namespace to avoid std:: before cout int main() { time_t currentTime = time(nullptr); struct tm* timeInfo = localtime(¤tTime); // using tm structure if (timeInfo == nullptr) { cerr << "Error getting local time." << endl; return 1; } int dayOfWeek = timeInfo->tm_wday; // 0 = Sunday, 1 = Monday, ..., 6 = Saturday switch (dayOfWeek) { case 0: cout << "Today is Sunday." << endl; break; case 1: cout << "Today is Monday." << endl; break; case 2: cout << "Today is Tuesday." << endl; break; case 3: cout << "Today is Wednesday." << endl; break; case 4: cout << "Today is Thursday." << endl; break; case 5: cout << "Today is Friday." << endl; break; case 6: cout << "Today is Saturday." << endl; break; default: cout << "It is not the name of a day." << endl; break; } return 0; }