date class with member functions

I am trying to create a date class with member funtions. I would like to set it up when you input 1-12 it will output January-December. Would I use a while loop or is there another way?
Last edited on
While loop? Class?

It sounds like you need a function. You place the names in a static array and the function goes a lookup.
char *names_of_months[12]={"January","February","March","April","May","June","July","August","September","October","November","December"};
All you need is that.
O ok. Because I tried if (mm = 1) but couldnt get it to work
return "January"
I will try your way
Remember that with this approach january is 0. You'll need to subtract 1.
ok cool. this is what I came up with so far with your suggestion.

// This program demonstrates the Date class.
#include <iostream>
#include <cctype>
#include <iomanip>
#include <string>
#include <locale>
using namespace std;

// Function prototypes
void displayMenu();


int main()
{
locale loc;
string str="first line \n second line \n";
for (size_t i=0; i<str.length(); ++i)
{
if (!isprint(str[i])) break;
cout << str[i];

char *names_of_months[12]=
{"January","February","March","April","May","June","July","August","September","October","November","December"};
typedef time_get<char> tg;
locale loc;
time_get<char>::dateorder order;
order = use_facet<time_get<char> >(loc).date_order();
switch (order) {

char choice; //Menu Selection
int num;

// Display the menu and get a valid selection.
displayMenu();
cin >> choice;
{
cout << "Please choose a date format "
<< "of 1, 2, 3, 4:";
cin >> choice;
}

// Process the user's menu selection.
switch(choice)
{
case '1': cout << "00/00/00";
break;
case '2': cout << "Month 00, 0000 ";
break;
case '3': cout << "00 Month, 0000";
break;
}

do
{
if (choice = 1)
cout<< "Enter the Month\n";
cin>> num;
do
{
if (num < 1)
if (num > 12)
cout<<"ERROR INVALID \n";

cout<< "Enter the Day\n";
cin>> num;
do
{
if (num < 1)
if (num > 31)
cout<<"ERROR INVALID \n";

cout<< "Enter the Year\n";
cin>> num;

case time_get<char>::dmy : cout << "dmy"; break;
do
{
if (choice = 2)
cout<< "Enter the Month\n";
cin>> num;

{

cout<< "Enter the Day\n";
cin>> num;
do
{
if (num < 1)
if (num > 31)
cout<<"ERROR INVALID \n";

cout<< "Enter the Year\n;
cin>> num;
case time_get<char>::dmy : cout << "mdy"; break;
Many errors in the code ....incomplete code , incomplete while loop.
Topic archived. No new replies allowed.