C++ char array Prints the day of the week based on an input value.

Description

C++ char array Prints the day of the week based on an input value.

#include <iostream>
using namespace std;
void main()/* w w  w  . ja v a2s  .  c om*/
{
   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;
}



PreviousNext

Related