Prints the day of the week based on an input value. - C++ Data Type

C++ examples for Data Type:char array

Description

Prints the day of the week based on an input value.

Demo Code

#include <iostream>
using namespace std;
void main()/*from  w  w w  .  j av  a2s.co m*/
{
   char *days[] = {"Sunday",   "Monday",        "Tuesday","Wednesday","Thursday","Friday","Saturday"};
   int day_num;
   do
   {
      cout << "What is a day number (from 1 to 7)? ";
      cin >> day_num;
   } while ((day_num<1) || (day_num>7));     // Ensures an accurate number.
   day_num--;                    // Adjusts for subscript.
   cout << "The day is " << *(days+day_num) << "\n";
   return;
}

Result


Related Tutorials