473,320 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to find how many days to someones bithday

2
I am brand new to programing and am trying to write a C++ program that calculates how many days are left to a persons birthday. I need to make a function for the leap years, and to get number of days in a month, i have no idea how to do this. any help would be great..
i am using windows op, with visual studios 2005
this is what i have so far.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int    getdate (int& day, int& month, int& year);
  5.  
  6.  
  7.  
  8. int main ()
  9. {
  10.  
  11.     int day, month, year;
  12.  
  13.     getdate (day, month, year);
  14.     cout << "The date you enterd is:\n";
  15.     cout << day <<endl << month <<endl << year <<endl;
  16.  
  17.  
  18.  
  19.     return 0;
  20. }
  21.  
  22.  
  23. int getdate (int& day,int& month,int& year)
  24. {
  25.     cout << "Please enter your birth day\n";
  26.     cout << "Day: ";
  27.     cin >> day;
  28.     cout << "Month (ex 4): ";
  29.     cin >> month;
  30.     cout << "year: ";
  31.     cin >> year;
  32.     return day, month, year;
  33. }
Nov 24 '07 #1
4 2890
Ganon11
3,652 Expert 2GB
Most of these are hard-coded numbers (i.e. January always has 31 days, there are always 12 months, etc.). You have the problem of deciding whether a given year is a leap year or not (if it is, February has 29 days - if not, February has 28 days), which is a simple mathematical test.

Now you have a day, month, and year. It should be simple addition/subtraction to find exactly how many days it is from Day A to Day B.

I'm seeing an array of integers for the days in a month (numbered from 0 to 11), a function isLeapYear(int year) to find out whether year is a leap year, and then a function calculateDays that will either take two Date structs (which you would make yourself), or two sets of month, date, and year integer variables.
Nov 24 '07 #2
cjohns
2
so would it look like this? i have yet to do the days in months. and how would i incorporate the bool variable into the program?

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int    getdate (int& day, int& month, int& year);
  5. int currentdate (int&day, int& month, int& year);
  6. int getnumberofdaysinmonth (int& month, int& year);
  7. bool isleapyear (int year);
  8. int main ()
  9. {
  10.  
  11.     int day, month, year;
  12.  
  13.     getdate (day, month, year);
  14.     cout << "The date you enterd is:\n";
  15.     cout << day <<endl << month <<endl << year <<endl << endl;
  16.     currentdate (day, month, year);
  17.     cout << "The date you enterd is:\n";
  18.     cout << day <<endl << month <<endl << year <<endl << endl;
  19.  
  20.     return 0;
  21. }
  22.  
  23.  
  24. int getdate (int& day,int& month,int& year)
  25. {
  26.     cout << "Please enter your birth day\n";
  27.     cout << "Day: ";
  28.     cin >> day;
  29.     cout << "Month (ex 4): ";
  30.     cin >> month;
  31.     cout << "year: ";
  32.     cin >> year;
  33.     return day, month, year;
  34. }
  35.  
  36. int currentdate (int&day, int& month, int& year)
  37. {
  38.     cout << "Please enter current date\n";
  39.     cout << "Day: ";
  40.     cin >> day;
  41.     cout << "Month (ex 4): ";
  42.     cin >> month;
  43.     cout << "year: ";
  44.     cin >> year;
  45.     return day, month, year;
  46. }
  47.  
  48.  
  49. bool IsLeapYear (int year)
  50. {    
  51.     bool rtn;
  52.     rtn = false;            
  53.         if ((year % 400) == 0)  
  54.         {                      
  55.             rtn = true;
  56.         }
  57.  
  58.         else if ((year % 100) == 0)  
  59.         {                       
  60.             rtn = false;        
  61.         }
  62.  
  63.          else if ((year % 4) == 0)   
  64.         {                       
  65.             rtn = true;
  66.         }
  67.     return rtn;            
  68.  
  69. }
Nov 24 '07 #3
JosAH
11,448 Expert 8TB
Google for "Zeller's congruence" (WFC will hate me for this ;-) That little formula
calculates a Julian day number for a date; the difference between two dates
expressed as Julian day numbers is the numerical difference between those numbers.

kind regards,

Jos
Nov 24 '07 #4
Ganon11
3,652 Expert 2GB
Your return statements are not only wrong, but unnecessary.

You can only return one thing at a time. You cannot return three ints, or five doubles, or multiple anything. You can return one int, one double, a pointer to something, or one struct variable. Thus, saying "return date, month, year;" may be syntactically acceptable, but it's not what you want to do.

Also, you are passing your variables 'by reference', meaning whatever changes occurring in the function are reflected in the place where they were called (in this case, in main()). So there's no need to return anything - you can make these functions return nothing by replacing "int getdate()..." with "void getdate()..." and deleting your return statement.
Nov 25 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: Tor Erik Sønvisen | last post by:
Hi I need to browse the socket-module source-code. I believe it's contained in the file socketmodule.c, but I can't locate this file... Where should I look? regards tores
90
by: Bret Pehrson | last post by:
This message isn't spam or an advertisement or trolling. I'm considering farming some of my application development to offshore shops (I'm in the US). I have absolutely *no* experience w/ this,...
2
by: project | last post by:
anybody can tell me how to find how many days in a month by using sql quiery Posted Via Usenet.com Premium Usenet Newsgroup Services ----------------------------------------------------------...
7
by: jnikle | last post by:
I have a database in A2003 format that's giving me this error, but it's not the same situation I've been reading about on here. In my development copy, I have imported copies of the backend's...
5
by: could.net | last post by:
I want to get these 2 values in c++ without using mfc: 1. how many days between current date and 0001-1-1 2. how many milliseconds elapsed since 00:00 of today. I would like to do this by only...
5
by: paulmac106 | last post by:
Hi. I utilize the Calendar table, and I'm able to find how many working days between 2 dates, but does anyone use this table to find the 2nd or 5th working date? if 11/30/06 then 12/4/06 ...
3
by: Nelson | last post by:
Hi All, I want to look at what happens to stock prices after a certain number of consecutive up or down days. Let's say, for instance, I'd like to see where a stock's price is 5 days after a...
0
by: ncrawford | last post by:
Hello All This is my first posting....and thanks in anticipation of help. Using MS Access 2000 I am recording sick days absence for individual employees. A StartDate and EndDate are entered...
1
by: EasyTarget | last post by:
Hello All: I am trying to write a query to determine the number of consecutive days that a conference room is available. The conference room is reserved for an entire day. People want to reserve...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.