Hey can someone help me, my program has to do with dates, and asks the user to input a date on or after 1/1/1800, take that date and compare these statistics to my birthday(1/20/84)
If the year is a leapyear
how many days the month in the dates have
one day prior and after the dates
----I got all that covered---

***all i need help with is how to output what number out of 365 days of the year is that day in that year. (taking in part if that year is a leapyear or not)
Thanx

Since you have functions that determine

If the year is a leapyear
how many days the month in the dates have

the rest is easy.

Your function to output the number out of the total days in an year should be something like this

``````int ReturnNumberOutOfTotalDays( Date date )
{
int days = 0 ;
// Add the maximum days in the months excluding the current month
for ( int i = 1 ; i <= date.month - 1 ; i++ ) // assuming you started your months from 1
{
days += MaxDaysOfMonth( date.year, i ) ; // this function should output 29 in the case of date.year is leap and i == 2
}
// Add the days gone by in this month
days += date.day;
return days;
}``````

hmm..

if the date is in the month of Jan or before/on Feb 29 it will not matter whether the year is leap or not.

Now we know that Jan,March,May,July,Aug,Oct,Dec has 31 days and the rest 30 days with the exception of Feb which can have 28 or 29 days.

On way is to generate a table with the days within a month. How you do this is not important, you can hard code it or use a for loop to generate it.

Hint: If you want to find out if a month has 30 or 31 days there's a simple method which is taught to children. They are asked to make a fist and are asked to say the names of the month, touching their knuckles (starting usually from the knuckle of the little finger) and the shallows between the knuckles. So it starts with Jan on the little finger knuckle, feb on the next shallow, March on the next knuckle etc etc. All the months which land on a knuckle have 31 days. When the last knuckle, i.e the index finger knuckle is reached, you go back to the first (i.e the little finger knuckle)

So anyways you make a table of months with the adjustment neccessary for feb. Then you add all the days of the months before the required date's month.Then you add the date to the sum you got. And you have the day of the year in which the date falls on.

Helps?

im still kinda confused ill put it in the program ill attatch my program it needs to count how many days out of 365 is that date entered taking in part the leap year and the days of the month necessary for each month as you can see in my program i did all that.

``````#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;

class Date
{
public:
// Constructors
Date();  // default constructor
Date(int m, int d, int y);

// other member functions
void output_numeric();
void output_string();
int get_month();
int get_day();
int get_year();
void set_to_nextday();
void set_to_prevday();
bool is_leap();
int monthdays();
int yeardays();

private:
int DaysInSuchMonth();
void check_date();
int month;
int day;
int year;
string dayTostring(int month);
};

int main()
{

Date bday(3,10,1986);
Date bday1(3,10,1986);
Date bday2(3,10,1986);
int m, d, y;
cout <<"Enter a date on or after 1/1/1800 in the form month/day/year:";
char ch;
cin >> m >> ch >> d >> ch >> y;
Date someday(m,d,y);
Date someday1(m,d,y);
Date someday2(m,d,y);
cout<<endl;
cout<<"You entered the date ";
someday.output_string();
cout<<endl;

cout<<"My birthday is on ";
bday.output_string();
cout<<endl<<endl;

cout<< "The year you entered, "<<someday.get_year()<<", is ";
if(!someday.is_leap())
cout<<"NOT";
cout<<" a leap year."<<endl;

cout<<"My birthday year, "<<bday.get_year()<<", is ";
if(!bday.is_leap())
cout<<"NOT";
cout<<" a leap year."<<endl<<endl;

cout<<"The month of the date you entered has "<<someday.monthdays()<<" days."<<endl;  cout<<"The month of my birthday has "<<bday.monthdays()<<" days."<<endl<<endl;

someday.set_to_prevday();
bday.set_to_prevday();

cout<<"One day prior to the date you entered, the date is ";
someday.output_string();
cout<<endl;

cout<<"One day prior to my birthday, the date is ";
bday.output_string();
cout<<endl<<endl;

someday.set_to_nextday();
someday.set_to_nextday();
bday.set_to_nextday();
bday.set_to_nextday();

cout<<"One day after the date you entered, the date is ";
someday.output_string();
cout<<endl;

cout<<"One day after my birthday, the date is ";
bday.output_string();
cout<<endl<<endl;

cout<<"C++ programs have class!! Goodbye..."<<endl;
return 0;
}

Date::Date()
{
month = 1;
day = 1;
year = 1800;
}

Date::Date(int m, int d, int y)
{
month= m;
day= d;
year= y;
check_date();
}

void Date::output_numeric()
{
cout <<month<< "/"<<day<<"/"<<year;
}

void Date::output_string()
{
cout<<dayTostring(month)<< " "<<day<<", "<<year<<".";
}

string Date::dayTostring(int month)
{
switch (month)
{
case 1: return "January";
case 2: return "February";
case 3: return "March";
case 4: return "April";
case 5: return "May";
case 6: return "June";
case 7: return "July";
case 8: return "August";
case 9: return "September";
case 10: return "October";
case 11: return "November";
case 12: return "December";
}

}

int Date::get_month()
{
return month;
}

int Date::get_day()
{
return day;
}

int Date::get_year()
{
return year;
}

void Date::check_date()
{
if ((month < 1) || (month > 12) || (day < 1) || (day > monthdays()) || (year < 1800))
{
cout << "Invalid date!"<< endl;
exit(1);
}
}

bool Date::is_leap()
{
if ((year%400)==0)
return true;
else if((year%4)==0)
return true;
else
return false;
}

int Date::DaysInSuchMonth()
{
switch(month)
{
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
return 31;
case 2:
if (is_leap())
return 29;
else
return 28;
default:
return 30;
}
}

int Date::monthdays()
{
return DaysInSuchMonth();
}

int Date::yeardays()
{
if (is_leap())
return 366;
else
return 365;
}

void Date::set_to_nextday()
{
if (++day>monthdays())
{
day=1;
if (++month >12)
{
month =1;
year++;
}
}

}

void Date::set_to_prevday()
{
if (--day < 1)
{
if (--month<1)
{
month = 12;
year--;
}
day=monthdays();
}
check_date();
}
``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.