Beginners Task #1

Online C++ programming contests.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard, raimo

uh?

Postby darkmaster » Tue May 18, 2004 4:28 pm

uh?? didn't understand what you meant. :oops:


Guest wrote:I doubt your cases are what you intend.
Code: Select all
#include <iostream>

int main()
{
   std::cout << ((1) | (21) | (31)) << std::endl;
   std::cout << ((2) | (22))        << std::endl;
   std::cout << ((3) | (23))        << std::endl;
   return 0;
}

/* my output
31
22
23
*/
The are not separate cases, they are the bitwise ORing of the values.



I think what you meant is that my switch in suffix function is wrong, but it isn't , it is supposed to cout "st" when the number is 1, 21 or 31, so it would be 1st, 21st or 31st , same with the others, and when is none of them it couts "th" so 25th , 6th,...
Last edited by darkmaster on Tue May 18, 2004 4:48 pm, edited 1 time in total.
User avatar
darkmaster
 
Posts: 27
Joined: Mon Mar 29, 2004 6:11 pm

Postby Guest » Tue May 18, 2004 4:39 pm

go home wrote:That is obviously Dave Sinkula so go back to http://cboard.cprogramming.com/index.php? and stay there.
Last edited by Guest on Thu Jan 06, 2005 1:20 am, edited 1 time in total.
Guest
 

fg

Postby darkmaster » Tue May 18, 2004 4:43 pm

Hi again.

Thanks for the else if tip, about de cases, i'm not having problems with them, if you want to, you can compile it and see it working.
User avatar
darkmaster
 
Posts: 27
Joined: Mon Mar 29, 2004 6:11 pm

Postby Guest » Tue May 18, 2004 4:45 pm

go home wrote:That is obviously Dave Sinkula so go back to http://cboard.cprogramming.com/index.php? and stay there.
Last edited by Guest on Thu Jan 06, 2005 1:20 am, edited 1 time in total.
Guest
 

f

Postby darkmaster » Tue May 18, 2004 4:53 pm

Opss.. I'm very sorry, now i see what you meant, thanks a lot. :wink:
User avatar
darkmaster
 
Posts: 27
Joined: Mon Mar 29, 2004 6:11 pm

fixed

Postby darkmaster » Tue May 18, 2004 5:00 pm

ok, i fixed my code and now it works

Code: Select all
#include <iostream>
using namespace std;

void suffix(int nday)
{
   switch(nday)
   {
      case (1) : cout << "st";
                 break;
      case (21) : cout << "st";
                 break;
      case (31) : cout << "st";
                 break;

      case (2) : cout << "nd";
                 break;
      case (22) : cout << "nd";
                 break;

      case (3) : cout << "rd";
                 break;
     case (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 ";
}

else if ((dayn > jan) && (dayn <= feb)) //February
   {
   cout << (febd);
   suffix(febd);
   cout << " February 2004 ";
   }

else if ((dayn > feb) && (dayn <= mar)) //March
   {
   cout << (mard);
   suffix(mard);
   cout << " March 2004 ";
   }

else if ((dayn > mar) && (dayn <= apr)) //April
   {
   cout << (aprd);
   suffix(aprd);
   cout << " April 2004 ";
   }

else if ((dayn > apr) && (dayn <= may)) //May
   {
   cout << (mayd);
   suffix(mayd);
   cout << " May 2004 ";
   }

else if ((dayn > may) && (dayn <= jun)) //June
   {
   cout << (jund);
   suffix(jund);
   cout << " June 2004 ";
   }

else if ((dayn > jun) && (dayn <= jul)) //July
   {
   cout << (juld);
   suffix(juld);
   cout << " July 2004 ";
   }

else if ((dayn > jul) && (dayn <= aug)) //August
   {
   cout << (augd);
   suffix(augd);
   cout << " August 2004 ";
   }

else if ((dayn > aug) && (dayn <= sep)) //September
   {
   cout << (sepd);
   suffix(sepd);
   cout << " September 2004 ";
   }

else if ((dayn > sep) && (dayn <= oct)) //October
   {
   cout << (octd);
   suffix(octd);
   cout << " October 2004 ";
   }

else if ((dayn > oct) && (dayn <= nov)) //November
   {
   cout << (novd);
   suffix(novd);
   cout << " November 2004 ";
   }

else if ( (dayn > nov) && (dayn <= dec) ) //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);
}
User avatar
darkmaster
 
Posts: 27
Joined: Mon Mar 29, 2004 6:11 pm

Re: fixed

Postby Guest » Wed May 19, 2004 7:49 am

go home wrote:That is obviously Dave Sinkula so go back to http://cboard.cprogramming.com/index.php? and stay there.
Last edited by Guest on Thu Jan 06, 2005 1:20 am, edited 1 time in total.
Guest
 

Postby tomcant » Wed May 19, 2004 12:05 pm

Heres my Win32 version. What do you all think?

Code: Select all
/***************************************************************

Name:   Calendar Application
Module: main.cpp
Author: Tom Cant

Note:   This code is freeware, however, you may not publish
        this code elsewhere or charge any money for it. This
        code is supplied as-is. I make no guarantees about the
        suitablitity of this code, use it at your own risk.

***************************************************************/

#include <windows.h>
#include <commctrl.h>
#include <cstdlib>

LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK EditProc(HWND, UINT, WPARAM, LPARAM);

static WNDPROC   originalEditProc;

char* suffix(int);

char szClassName[ ] = "Win32App";
char *szDay = new char;
char *szError = "Invalid entry - must be between 1 and 365!";

int  day;

#define IDC_EDIT        101
#define IDC_CALCULATE   102

static HWND    hText        = NULL;
static HWND    hEdit        = NULL;
static HWND    hCalc        = NULL;

struct month
{
   int start;
   int end;
   int days;
};

month Jan = { 1, 31, 31 };
month Feb = { 32, 61, 28 };
month Mar = { 62, 93, 31 };
month Apr = { 94, 124, 30 };
month May = { 125, 156, 31 };
month Jun = { 157, 187, 30 };
month Jul = { 188, 219, 31 };
month Aug = { 220, 251, 31 };
month Sep = { 252, 282, 30 };
month Oct = { 283, 314, 31 };
month Nov = { 315, 345, 30 };
month Dec = { 346, 365, 31 };

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
    HWND hwnd;
    MSG msg;
    WNDCLASSEX wincl;

    wincl.hInstance     = hInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc   = WindowProcedure;
    wincl.style         = CS_DBLCLKS;
    wincl.cbSize        = sizeof(WNDCLASSEX);
    wincl.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wincl.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    wincl.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wincl.lpszMenuName  = NULL;
    wincl.cbClsExtra    = 0;
    wincl.cbWndExtra    = 0;
    wincl.hbrBackground = (HBRUSH) (COLOR_WINDOW);

    if(!RegisterClassEx(&wincl)) return 0;

    hwnd = CreateWindowEx(
           0,
           szClassName,
           "Calendar - by Tom Cant",
           WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX,
           GetSystemMetrics(SM_CXSCREEN)/7, GetSystemMetrics(SM_CYSCREEN)/7,
           330, 63,
           HWND_DESKTOP,
           NULL,
           hInstance,
           NULL
           );

    if(hwnd == NULL)
    {
        MessageBox(0, "Window Creation Failed!", "Error...", MB_OK);
        return 0;
    }

    ShowWindow(hwnd, SW_SHOW);
    UpdateWindow(hwnd);

    while(GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return (int)msg.wParam;
}

LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_DESTROY:
            {
                PostQuitMessage(0);
            }

            break;

        case WM_LBUTTONDOWN:
            {
                SendMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);
            }

            break;

        case WM_CREATE:
            {
                hText = CreateWindow(
                        "static",
                        "Enter a number:",
                        WS_VISIBLE | WS_CHILD | SS_SIMPLE,
                        10, 10,
                        105, 17,
                        hwnd,
                        (HMENU)1,
                        GetModuleHandle(NULL),
                        NULL
                        );

                hEdit = CreateWindowEx(
                        WS_EX_CLIENTEDGE,
                        "edit",
                        (LPCSTR)NULL,
                        WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL | ES_NUMBER,
                        125, 7,
                        75, 23,
                        hwnd,
                        (HMENU)IDC_EDIT,
                        GetModuleHandle(NULL),
                        NULL
                        );

                originalEditProc = (WNDPROC)SetWindowLong(hEdit, GWL_WNDPROC, (LONG)EditProc);

                hCalc = CreateWindow(
                        "button",
                        "Calculate",
                        WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
                        220, 7,
                        95, 23,
                        hwnd,
                        (HMENU)IDC_CALCULATE,
                        GetModuleHandle(NULL),
                        NULL
                        );
            }

            break;

        case WM_KEYDOWN:
            {
                if(wParam == VK_RETURN)
                {
                    SendMessage(hCalc, BM_CLICK, 0, 0);
                }
            }

            break;

        case WM_COMMAND:
            {
                switch(LOWORD(wParam))
                {
                    case IDC_CALCULATE:
                        {
                            // Pseudo Code:
                            //
                            // 1. Get number from edit box
                            // 2. Check if number is valid (ie. > 0 & < 365)
                            // 3. Do calculation on day
                            // 4. Display date in a message box

                            day = GetDlgItemInt(hwnd, IDC_EDIT, NULL, false);

                            if((day < 1) | (day > 365))
                            {
                              MessageBox(hwnd, szError, "Calendar", MB_OK);
                            }
                            else
                            {
                              if((day >= Jan.start) && (day <= Jan.end)) // January
                              {
                                 int day_num = day;
                                 wsprintf(szDay, "%d%s January 2004", day_num, suffix(day_num));
                              }
                              else if((day >= Feb.start) && (day <= Feb.end)) // February
                              {
                                 int day_num = day-Jan.days;
                                 wsprintf(szDay, "%d%s February 2004", day_num, suffix(day_num));
                              }
                              else if((day >= Mar.start) && (day <= Mar.end)) // March
                              {
                                 int day_num = day-Jan.days-Feb.days;
                                 wsprintf(szDay, "%d%s March 2004", day_num, suffix(day_num));
                              }
                              else if((day >= Apr.start) && (day <= Apr.end)) // April
                              {
                                 int day_num = day-Jan.days-Feb.days-Mar.days;
                                 wsprintf(szDay, "%d%s April 2004", day_num, suffix(day_num));
                              }
                              else if((day >= May.start) && (day <= May.end)) // May
                              {
                                 int day_num = day-Jan.days-Feb.days-Mar.days-Apr.days;
                                 wsprintf(szDay, "%d%s May 2004", day_num, suffix(day_num));
                              }
                              else if((day >= Jun.start) && (day <= Jun.end)) // June
                              {
                                 int day_num = day-Jan.days-Feb.days-Mar.days-Apr.days-May.days;
                                 wsprintf(szDay, "%d%s June 2004", day_num, suffix(day_num));
                              }
                              else if((day >= Jul.start) && (day <= Jul.end)) // July
                              {
                                 int day_num = day-Jan.days-Feb.days-Mar.days-Apr.days-May.days-Jun.days;
                                 wsprintf(szDay, "%d%s July 2004", day_num, suffix(day_num));
                              }
                              else if((day >= Aug.start) && (day <= Aug.end)) // August
                              {
                                 int day_num = day-Jan.days-Feb.days-Mar.days-Apr.days-May.days-Jun.days-Jul.days;
                                 wsprintf(szDay, "%d%s August 2004", day_num, suffix(day_num));
                              }
                              else if((day >= Sep.start) && (day <= Sep.end)) // September
                              {
                                 int day_num = day-Jan.days-Feb.days-Mar.days-Apr.days-May.days-Jun.days-Jul.days-Aug.days;
                                 wsprintf(szDay, "%d%s September 2004", day_num, suffix(day_num));
                              }
                              else if((day >= Oct.start) && (day <= Oct.end)) // October
                              {
                                 int day_num = day-Jan.days-Feb.days-Mar.days-Apr.days-May.days-Jun.days-Jul.days-Aug.days-Sep.days;
                                 wsprintf(szDay, "%d%s October 2004", day_num, suffix(day_num));
                              }
                              else if((day >= Nov.start) && (day <= Nov.end)) // November
                              {
                                 int day_num = day-Jan.days-Feb.days-Mar.days-Apr.days-May.days-Jun.days-Jul.days-Aug.days-Sep.days-Oct.days;
                                 wsprintf(szDay, "%d%s November 2004", day_num, suffix(day_num));
                              }
                              else if((day >= Dec.start) && (day <= Dec.end)) // December
                              {
                                 int day_num = day-Jan.days-Feb.days-Mar.days-Apr.days-May.days-Jun.days-Jul.days-Aug.days-Sep.days-Oct.days-Nov.days;
                                 wsprintf(szDay, "%d%s December 2004", day_num, suffix(day_num));
                              }

                              MessageBox(hwnd, szDay, "Calendar", MB_OK);
                            }
                        }

                        SetFocus(hEdit);

                        break;
                }
            }

            break;

        default:
            {
                return DefWindowProc(hwnd, msg, wParam, lParam);
            }
    }

    return 0;
}

char* suffix(int day)
{
   if((day == 1) | (day == 21) | (day == 31))
   {
      return("st");
   }
   else if((day == 2) | (day == 22))
   {
      return("nd");
   }
   else  if((day == 3) | (day == 23))
   {
      return("rd");
   }
   else
   {
      return("th");
   }
}

LRESULT CALLBACK EditProc(HWND hEdit, UINT Msg, WPARAM wParam, LPARAM lParam)
{
    switch(Msg)
    {
      case WM_KEYDOWN:
      {
        if(wParam == VK_RETURN)
        {
          SendMessage(hCalc, BM_CLICK, 0, 0);
        }

        return 0;
      }

      default:
      {
        return CallWindowProc(originalEditProc, hEdit, Msg, wParam, lParam);
      }
  }
}
If it wasn't for C, we would be using BASI, PASAL and OBOL.
User avatar
tomcant
 
Posts: 3101
Joined: Tue Sep 23, 2003 1:56 am
Location: Colchester, UK

Postby Guest » Wed May 19, 2004 12:21 pm

go home wrote:That is obviously Dave Sinkula so go back to http://cboard.cprogramming.com/index.php? and stay there.
Last edited by Guest on Thu Jan 06, 2005 1:23 am, edited 1 time in total.
Guest
 

Postby tomcant » Wed May 19, 2004 1:01 pm

Hmm. I dont understand that at all. I see the problems, but how to resolve them... :? My calculations are fine, I think.... ?
If it wasn't for C, we would be using BASI, PASAL and OBOL.
User avatar
tomcant
 
Posts: 3101
Joined: Tue Sep 23, 2003 1:56 am
Location: Colchester, UK

Postby Guest » Wed May 19, 2004 1:17 pm

go home wrote:That is obviously Dave Sinkula so go back to http://cboard.cprogramming.com/index.php? and stay there.
Last edited by Guest on Thu Jan 06, 2005 1:23 am, edited 1 time in total.
Guest
 

Postby tomcant » Wed May 19, 2004 1:28 pm

Yes, I see :)

Does anyone know how to test if this year is a leap year?
If it wasn't for C, we would be using BASI, PASAL and OBOL.
User avatar
tomcant
 
Posts: 3101
Joined: Tue Sep 23, 2003 1:56 am
Location: Colchester, UK

Postby Guest » Wed May 19, 2004 1:35 pm

go home wrote:That is obviously Dave Sinkula so go back to http://cboard.cprogramming.com/index.php? and stay there.
Last edited by Guest on Thu Jan 06, 2005 1:23 am, edited 1 time in total.
Guest
 

Postby tomcant » Wed May 19, 2004 1:38 pm

Well, heres a correct version for this year only.

Code: Select all
/***************************************************************

Name:   Calendar Application
Module: main.cpp
Author: Tom Cant

Note:   This code is freeware, however, you may not publish
        this code elsewhere or charge any money for it. This
        code is supplied as-is. I make no guarantees about the
        suitablitity of this code, use it at your own risk.

***************************************************************/

#include <windows.h>
#include <commctrl.h>
#include <cstdlib>

LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK EditProc(HWND, UINT, WPARAM, LPARAM);

static WNDPROC   originalEditProc;

char* suffix(int);

char szClassName[ ] = "Win32App";
char *szDay = new char;
char *szError = "Invalid entry - must be between 1 and 365!";

int  day;

#define IDC_EDIT        101
#define IDC_CALCULATE   102

static HWND    hText        = NULL;
static HWND    hEdit        = NULL;
static HWND    hCalc        = NULL;

struct month
{
   int start;
   int end;
   int days;
};

month Jan = {   1,  31,  31 };
month Feb = {  32,  59,  28 };
month Mar = {  60,  90,  31 };
month Apr = {  91, 120,  30 };
month May = { 121, 151,  31 };
month Jun = { 152, 181,  30 };
month Jul = { 182, 212,  31 };
month Aug = { 213, 243,  31 };
month Sep = { 244, 273,  30 };
month Oct = { 274, 304,  31 };
month Nov = { 305, 334,  30 };
month Dec = { 335, 365,  31 };

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
    HWND hwnd;
    MSG msg;
    WNDCLASSEX wincl;

    wincl.hInstance     = hInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc   = WindowProcedure;
    wincl.style         = CS_DBLCLKS;
    wincl.cbSize        = sizeof(WNDCLASSEX);
    wincl.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wincl.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    wincl.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wincl.lpszMenuName  = NULL;
    wincl.cbClsExtra    = 0;
    wincl.cbWndExtra    = 0;
    wincl.hbrBackground = (HBRUSH) (COLOR_WINDOW);

    if(!RegisterClassEx(&wincl)) return 0;

    hwnd = CreateWindowEx(
           0,
           szClassName,
           "Calendar - by Tom Cant",
           WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX,
           GetSystemMetrics(SM_CXSCREEN)/7, GetSystemMetrics(SM_CYSCREEN)/7,
           330, 63,
           HWND_DESKTOP,
           NULL,
           hInstance,
           NULL
           );

    if(hwnd == NULL)
    {
        MessageBox(0, "Window Creation Failed!", "Error...", MB_OK);
        return 0;
    }

    ShowWindow(hwnd, SW_SHOW);
    UpdateWindow(hwnd);

    while(GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return (int)msg.wParam;
}

LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_DESTROY:
            {
                PostQuitMessage(0);
            }

            break;

        case WM_LBUTTONDOWN:
            {
                SendMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);
            }

            break;

        case WM_CREATE:
            {
                hText = CreateWindow(
                        "static",
                        "Enter a number:",
                        WS_VISIBLE | WS_CHILD | SS_SIMPLE,
                        10, 10,
                        105, 17,
                        hwnd,
                        (HMENU)1,
                        GetModuleHandle(NULL),
                        NULL
                        );

                hEdit = CreateWindowEx(
                        WS_EX_CLIENTEDGE,
                        "edit",
                        (LPCSTR)NULL,
                        WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL | ES_NUMBER,
                        125, 7,
                        75, 23,
                        hwnd,
                        (HMENU)IDC_EDIT,
                        GetModuleHandle(NULL),
                        NULL
                        );

                originalEditProc = (WNDPROC)SetWindowLong(hEdit, GWL_WNDPROC, (LONG)EditProc);

                hCalc = CreateWindow(
                        "button",
                        "Calculate",
                        WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
                        220, 7,
                        95, 23,
                        hwnd,
                        (HMENU)IDC_CALCULATE,
                        GetModuleHandle(NULL),
                        NULL
                        );
            }

            break;

        case WM_KEYDOWN:
            {
                if(wParam == VK_RETURN)
                {
                    SendMessage(hCalc, BM_CLICK, 0, 0);
                }
            }

            break;

        case WM_COMMAND:
            {
                switch(LOWORD(wParam))
                {
                    case IDC_CALCULATE:
                        {
                            // Pseudo Code:
                            //
                            // 1. Get number from edit box
                            // 2. Check if number is valid (ie. > 0 & < 365)
                            // 3. Do calculation on day
                            // 4. Display date in a message box

                            day = GetDlgItemInt(hwnd, IDC_EDIT, NULL, false);

                            if((day < 1) | (day > 365))
                            {
                              MessageBox(hwnd, szError, "Calendar", MB_OK);
                            }
                            else
                            {
                              if((day >= Jan.start) && (day <= Jan.end)) // January
                              {
                                 int day_num = day;
                                 wsprintf(szDay, "%d%s January 2004", day_num, suffix(day_num));
                              }
                              else if((day >= Feb.start) && (day <= Feb.end)) // February
                              {
                                 int day_num = day-Jan.days;
                                 wsprintf(szDay, "%d%s February 2004", day_num, suffix(day_num));
                              }
                              else if((day >= Mar.start) && (day <= Mar.end)) // March
                              {
                                 int day_num = day-Jan.days-Feb.days;
                                 wsprintf(szDay, "%d%s March 2004", day_num, suffix(day_num));
                              }
                              else if((day >= Apr.start) && (day <= Apr.end)) // April
                              {
                                 int day_num = day-Jan.days-Feb.days-Mar.days;
                                 wsprintf(szDay, "%d%s April 2004", day_num, suffix(day_num));
                              }
                              else if((day >= May.start) && (day <= May.end)) // May
                              {
                                 int day_num = day-Jan.days-Feb.days-Mar.days-Apr.days;
                                 wsprintf(szDay, "%d%s May 2004", day_num, suffix(day_num));
                              }
                              else if((day >= Jun.start) && (day <= Jun.end)) // June
                              {
                                 int day_num = day-Jan.days-Feb.days-Mar.days-Apr.days-May.days;
                                 wsprintf(szDay, "%d%s June 2004", day_num, suffix(day_num));
                              }
                              else if((day >= Jul.start) && (day <= Jul.end)) // July
                              {
                                 int day_num = day-Jan.days-Feb.days-Mar.days-Apr.days-May.days-Jun.days;
                                 wsprintf(szDay, "%d%s July 2004", day_num, suffix(day_num));
                              }
                              else if((day >= Aug.start) && (day <= Aug.end)) // August
                              {
                                 int day_num = day-Jan.days-Feb.days-Mar.days-Apr.days-May.days-Jun.days-Jul.days;
                                 wsprintf(szDay, "%d%s August 2004", day_num, suffix(day_num));
                              }
                              else if((day >= Sep.start) && (day <= Sep.end)) // September
                              {
                                 int day_num = day-Jan.days-Feb.days-Mar.days-Apr.days-May.days-Jun.days-Jul.days-Aug.days;
                                 wsprintf(szDay, "%d%s September 2004", day_num, suffix(day_num));
                              }
                              else if((day >= Oct.start) && (day <= Oct.end)) // October
                              {
                                 int day_num = day-Jan.days-Feb.days-Mar.days-Apr.days-May.days-Jun.days-Jul.days-Aug.days-Sep.days;
                                 wsprintf(szDay, "%d%s October 2004", day_num, suffix(day_num));
                              }
                              else if((day >= Nov.start) && (day <= Nov.end)) // November
                              {
                                 int day_num = day-Jan.days-Feb.days-Mar.days-Apr.days-May.days-Jun.days-Jul.days-Aug.days-Sep.days-Oct.days;
                                 wsprintf(szDay, "%d%s November 2004", day_num, suffix(day_num));
                              }
                              else if((day >= Dec.start) && (day <= Dec.end)) // December
                              {
                                 int day_num = day-Jan.days-Feb.days-Mar.days-Apr.days-May.days-Jun.days-Jul.days-Aug.days-Sep.days-Oct.days-Nov.days;
                                 wsprintf(szDay, "%d%s December 2004", day_num, suffix(day_num));
                              }

                              MessageBox(hwnd, szDay, "Calendar", MB_OK);
                            }
                        }

                        SetFocus(hEdit);

                        break;
                }
            }

            break;

        default:
            {
                return DefWindowProc(hwnd, msg, wParam, lParam);
            }
    }

    return 0;
}

char* suffix(int day)
{
   if((day == 1) | (day == 21) | (day == 31))
   {
      return("st");
   }
   else if((day == 2) | (day == 22))
   {
      return("nd");
   }
   else  if((day == 3) | (day == 23))
   {
      return("rd");
   }
   else
   {
      return("th");
   }
}

LRESULT CALLBACK EditProc(HWND hEdit, UINT Msg, WPARAM wParam, LPARAM lParam)
{
    switch(Msg)
    {
      case WM_KEYDOWN:
      {
        if(wParam == VK_RETURN)
        {
          SendMessage(hCalc, BM_CLICK, 0, 0);
        }

        return 0;
      }

      default:
      {
        return CallWindowProc(originalEditProc, hEdit, Msg, wParam, lParam);
      }
  }
}


I want to include a test for leap years :wink:
If it wasn't for C, we would be using BASI, PASAL and OBOL.
User avatar
tomcant
 
Posts: 3101
Joined: Tue Sep 23, 2003 1:56 am
Location: Colchester, UK

hg

Postby darkmaster » Wed May 19, 2004 5:03 pm

Hi :roll:

Can anyone tell how do I compile the code for the win calendar with vc++ 6.0 ?
:wink:
User avatar
darkmaster
 
Posts: 27
Joined: Mon Mar 29, 2004 6:11 pm

PreviousNext

Return to Contests

Who is online

Users browsing this forum: No registered users and 1 guest