C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 10th, 2006, 01:07 PM
andyp81 andyp81 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Posts: 1 andyp81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 55 sec
Reputation Power: 0
Unhappy C++ Date Problem, days of month, months from days

I have inherited some c++ code that uses MFC to calculate the months and days of that month from the day of year. i.e.
1 = 1 day, 1 month;
6 = 6 days, 1 month;
33 = 2 day, 2 month;
365 = 31 days, 12 month

The code previously used MFC classes to calculate the number of months and the days of that month from the total days since the start of the year.

I am looking for a c++ method that does not use MFC but can use win32 methods to calculate the number of days and number of months from the total number of days provided.

Reply With Quote
  #2  
Old February 10th, 2006, 05:23 PM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 997 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2Folding Points: 911244 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 14 h 26 m 27 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
Something like this:
c Code:
Original - c Code
  1. #include <stdio.h>
  2.  
  3. unsigned int daysformonth(unsigned int month, unsigned int year)
  4. {
  5.     /*  This function returns the number of days for the given month in the given year    */
  6.     return (30 + (((month & 9) == 8) || ((month & 9) == 1)) - (month == 2) - (!(((year % 4) == 0) && (((year % 100) != 0) || ((year % 400) == 0))) && (month == 2)));
  7. }
  8.  
  9. int main()
  10. {
  11.     /*  declarations  */
  12.     unsigned int numdays, month, year, maxdays;
  13.  
  14.     /*  get input */
  15.     printf("Please give number of days:");
  16.     scanf("%u", &numdays);
  17.     printf("Please give year:");
  18.     scanf("%u", &year);
  19.  
  20.     /*  calculate result  */
  21.    
  22.     for(month = 1; numdays > (maxdays = daysformonth(month, year)); month = (month == 12) ? 1 : (month + 1))
  23.     {
  24.         numdays -= maxdays;
  25.         if(month == 12)
  26.             year++;
  27.     }
  28.  
  29.     /*  output results    */
  30.     printf("Day %u for month %u in year %u\n", numdays, month, year);
  31.  
  32.     /*  return succes */
  33.     return 0;
  34. }


I had to add 'year' to the inputs, since you have to take leap years into account.
__________________
This is my code. Is it not nifty?

"The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools."
---Douglas Adams


Join the Itsacon fanclub!    
Zero Tolerance: Spammers banned so far: 280

Last edited by Itsacon : February 10th, 2006 at 05:27 PM.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > C++ Date Problem, days of month, months from days


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT