Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard, raimo
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(int argc, char *argv[])
{
int DofY = 1;
cout << "Please enter a number between 1-366: "<< endl;
cin >> DofY;
if (DofY < 31){
cout << DofY << " January 2004" << endl;}
else {
if (DofY < 60){
cout << (DofY - 31) << " February 2004" << endl;}
else{
if (DofY < 91){
cout << (DofY - 60) << " March 2004" << endl;}
else{
if (DofY < 121){
cout << (DofY - 91) << " April 2004" << endl;}
else{
if (DofY < 152){
cout << (DofY - 121) << " May 2004" << endl;}
else {
if (DofY < 182){
cout << (DofY - 152) << " June 2004" << endl;}
else{
if (DofY < 213){
cout << (DofY - 182) << " July 2004" << endl;}
else{
if (DofY < 244){
cout << (DofY - 213) << " August 2004" << endl;}
else{
if (DofY < 274){
cout << (DofY - 244) << " September 2004" << endl;}
else{
if (DofY < 305){
cout << (DofY - 274) << " October 2004" << endl;}
else{
if (DofY < 335){
cout << (DofY - 305) << " November 2004" << endl;}
else{cout << (DofY - 335) << " December 2004" << endl;}
}
}
}
}
}
}
}
}
}
} system("PAUSE");
return 0;
}
//MainFrame.cpp
#include "MainFrame.h"
#include "MyDialog.h"
#include <Afx.h>
CMyWinApp MyApplication;
BOOL CMyWinApp::InitInstance()
{
CMainFrame* pFrame = new CMainFrame;
m_pMainWnd = pFrame;
pFrame->ShowWindow(SW_SHOW);
pFrame->UpdateWindow();
return TRUE;
}
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_COMMAND (ID_SHOWDIALOG, ShowDialog)
END_MESSAGE_MAP()
CMainFrame::CMainFrame()
{
Create ( NULL,"Calendar",
WS_OVERLAPPEDWINDOW &~WS_THICKFRAME &~WS_MAXIMIZEBOX,
CRect(0,0,300,200),
NULL,
MAKEINTRESOURCE (IDR_MENU1)
);
mDay = 6;
}
void CMainFrame::ShowDialog()
{
CClientDC dc (this);
CMyDialog Dlg(this);
Invalidate();
Dlg.day = mDay;
if (Dlg.DoModal() == IDOK)
{
mDay = Dlg.day;
CString dayname[] = {"Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday"};
CString month[] = {"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
const int daystosubtract[]= { 0, 31, 60, 91, 121, 152,
182, 213, 244, 274, 305, 335 };//what number of days to subtract
int i = 0;
const int div = 32;
i = mDay / div; // which number from arry to use for subtraction
daystosubtract[i];
int daysofmonth = 0;
daysofmonth = mDay - daystosubtract[i]; // which day of the month
const int daysdiveder = 7;
int prefix = 0;
prefix = mDay / daysdiveder;
int g = 0;
g = prefix * daysdiveder;
int days = 0;
days = mDay - g;
int whichprefix = 0;
if ( (daysofmonth >= 4 && daysofmonth <= 20) || (daysofmonth >= 24 && daysofmonth <= 30))
{whichprefix = 5;}
else
whichprefix = daysofmonth % 10; //which prefix
switch (whichprefix)
{
case 1:
{
CString s;
s.Format ("Day: %s, %d st %s 2004", dayname[days], daysofmonth, month[i]);
dc.TextOut (10,10,s);
break;
}
case 2:
{
CString s;
s.Format ("Day: %s, %d nd %s 2004", dayname[days], daysofmonth, month[i]);
dc.TextOut (10,10,s);
break;
}
case 3:
{
CString s;
s.Format ("Day: %s, %d rd %s 2004", dayname[days], daysofmonth, month[i]);
dc.TextOut (10,10,s);
break;
}
default :
{
CString s;
s.Format ("Day: %s, %d th %s 2004", dayname[days], daysofmonth, month[i]);
dc.TextOut (10,10,s);
break;
}
}
}
else
dc.TextOut (10,10,"You press CANCEL");
}//MainFrame.h
#include <afxwin.h>
class CMyWinApp : public CWinApp
{
public:
virtual BOOL InitInstance();
};
class CMainFrame : public CFrameWnd
{
private:
int mDay;
public:
CMainFrame();
afx_msg void ShowDialog();
DECLARE_MESSAGE_MAP()
};
//MyDialog.cpp
#include "MyDialog.h"
CMyDialog::CMyDialog(CWnd* pParentWnd)
: CDialog (IDD_DIALOG1, pParentWnd)
{ }
CMyDialog::~CMyDialog() { }
BOOL CMyDialog::OnInitDialog()
{
SetDlgItemInt (IDC_DAY, day);
return TRUE;
}
void CMyDialog::OnOK()
{
day = GetDlgItemInt (IDC_DAY);
CDialog::OnOK();
}
//MyDialog.h
#include <afxwin.h>
#include "resource.h"
class CMyDialog : public CDialog
{
public:
int day;
CMyDialog(CWnd* pParentWnd);
virtual ~CMyDialog();
virtual BOOL OnInitDialog();
virtual void OnOK();
};//MyResScript.rc
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Menu
//
IDR_MENU1 MENU
BEGIN
MENUITEM "Enter Number", ID_SHOWDIALOG
END
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DIALOG1 DIALOGEX 0, 0, 119, 48
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Enter information"
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
DEFPUSHBUTTON "OK",IDOK,77,7,35,14
PUSHBUTTON "Cancel",IDCANCEL,73,27,39,14
RTEXT "Day",IDC_STATIC,7,28,21,13,SS_CENTERIMAGE
EDITTEXT IDC_DAY,35,29,23,12,ES_AUTOHSCROLL
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_DIALOG1, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 112
TOPMARGIN, 7
BOTTOMMARGIN, 41
END
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED//resource.h
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by MyResScript.rc
//
#define IDR_MENU1 101
#define IDD_DIALOG1 102
#define IDC_DAY 1001
#define IDC_IMAGELISTCTRL1 1002
#define ID_SHOWDIALOG 40001
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40002
#define _APS_NEXT_CONTROL_VALUE 1003
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
#include <iostream>
using namespace std;
void suffix(int nday)
{
switch(nday)
{
case ((1) | (21) | (31)) : cout << "st";
break;
case ((2) | (22)) : cout << "nd";
break;
case ((3) | (23)) : cout << "rd";
break;
default : cout << "th";
}
}
void date(int dayn)
{
int jan = 31;
int feb = 60;
int mar = 91;
int apr = 121;
int may = 152;
int jun = 182;
int jul = 213;
int aug = 244;
int sep = 274;
int oct = 305;
int nov = 335;
int dec = 366;
int febd = dayn - jan;
int mard = dayn - feb;
int aprd = dayn - mar;
int mayd = dayn - apr;
int jund = dayn - may;
int juld = dayn - jun;
int augd = dayn - jul;
int sepd = dayn - aug;
int octd = dayn - sep;
int novd = dayn - oct;
int decd = dayn - nov;
if (dayn <= jan) //January
{
cout << dayn;
suffix(dayn);
cout << " January 2004 ";
}
if ((dayn > jan) && (dayn < mar)) //February
{
cout << (febd);
suffix(febd);
cout << " February 2004 ";
}
if ((dayn > feb) && (dayn < apr)) //March
{
cout << (mard);
suffix(mard);
cout << " March 2004 ";
}
if ((dayn > mar) && (dayn < may)) //April
{
cout << (aprd);
suffix(aprd);
cout << " April 2004 ";
}
if ((dayn > apr) && (dayn < jun)) //May
{
cout << (mayd);
suffix(mayd);
cout << " May 2004 ";
}
if ((dayn > may) && (dayn < jul)) //June
{
cout << (jund);
suffix(jund);
cout << " June 2004 ";
}
if ((dayn > jun) && (dayn < aug)) //July
{
cout << (juld);
suffix(juld);
cout << " July 2004 ";
}
if ((dayn > jul) && (dayn < sep)) //August
{
cout << (augd);
suffix(augd);
cout << " August 2004 ";
}
if ((dayn > aug) && (dayn < nov)) //September
{
cout << (sepd);
suffix(sepd);
cout << " September 2004 ";
}
if ((dayn > sep) && (dayn < nov)) //October
{
cout << (octd);
suffix(octd);
cout << " October 2004 ";
}
if ((dayn > oct) && (dayn < dec)) //November
{
cout << (novd);
suffix(novd);
cout << " November 2004 ";
}
if ((dayn > nov) && (dayn <= 366)) //December
{
cout << (decd);
suffix(decd);
cout << " December 2004 ";
}
}
int main()
{
int day;
cout << "Enter a number between 1 and 366: ";
cin >> day;
if ((day >= 1) && (day <= 366))
{
date(day);
cin.ignore();
cin.get();
}
else {
cout << "Please enter a valid value";
cin.ignore();
cin.get();
}
return(0);
}go home wrote:That is obviously Dave Sinkula so go back to http://cboard.cprogramming.com/index.php? and stay there.
go home wrote:That is obviously Dave Sinkula so go back to http://cboard.cprogramming.com/index.php? and stay there.
Users browsing this forum: No registered users and 0 guests