Hi,
I need urgent help on my assignment...please don't assume I'm asking you to write my program..I just need a guide to start. I've lost my USB so I lost all my programs, and all the notes etc from class and I've been sick lately so haven't been attending class either...so I'm kinda..well really really lost...With that being said, here is the assignment :D
Write a program that prints the day number of the year, given the date in the form month-day-year. For example, if the input is 1-1-2006, the day number is 1; if the input is 12-25-2006, the day number is 359. The program should check for a leap year.

And This is what I have so far...

#include<iostream>
using namespace std;

int main()
{
	date;

	cout << "Please enter a date (mm-dd-yyyy): ";
	cint >> date;

	if ( date / 4 == 0 && date / 100 != 0)
	{
		/*leap year*/
	}
}

And now I'm confused as to what I should do...I need to divide the year to check for leap year...but the way I have my date, it won't work out...so, can someone guide me a bit ?
Thanks...

What data type is date? Can we assume it is a character array since you want to enter in mm-dd-yyyy format?

After entering the date it needs to be split up into month, day and year integers. Then to test for yeap use use the mod operator % on the year, i.e. if( year%4 == 0 ) Another way to do it is to use the mktime() function in time.h, which will produce the day-of-year that your assignment is looking for. But here again you have to split the string into individual integers.

Hi,
I need urgent help on my assignment...please don't assume I'm asking you to write my program..I just need a guide to start. I've lost my USB so I lost all my programs, and all the notes etc from class and I've been sick lately so haven't been attending class either...so I'm kinda..well really really lost...With that being said, here is the assignment :D
Write a program that prints the day number of the year, given the date in the form month-day-year. For example, if the input is 1-1-2006, the day number is 1; if the input is 12-25-2006, the day number is 359. The program should check for a leap year.

And This is what I have so far...

#include<iostream>
using namespace std;

int main()
{
	date;

	cout << "Please enter a date (mm-dd-yyyy): ";
	cint >> date;

	if ( date / 4 == 0 && date / 100 != 0)
	{
		/*leap year*/
	}
}

And now I'm confused as to what I should do...I need to divide the year to check for leap year...but the way I have my date, it won't work out...so, can someone guide me a bit ?
Thanks...

I don't know C++, just starting to learn
I can point out one thing only. The condition for leap year should be:

if(((year%4==0) && (year%100!=0)) ||(year%400==0))

because, years that are evenly divisible by 100 are not leap years, unless they are also evenly divisible by 400, in which case they are leap years.
Hope this gives ur code a perfection, once it is done.

Do note: that for years before 1582, leap years where EVERY 4 years.
There was no 400 or 100 year rule. Prior to 325 the system was
1582 is a mess. Since they did not have a 5-14th October completely (10 days).

It you are in in Britian/America it wasn't 1582 BUT 1752 and the days dropped needed to be 11. (September 2nd was next to the 14th).

So that makes the "correct program" very interesting problem.

@Ancient Dragon: umm..okay so I'll declare it as

char date[8];

like this ?
So then how do I split it...? Sorry I'm just completely lost.. =(
mhm Okay I understand the leap year test part...it's just the date that's throwing me off...
and the 2nd method you talked about, we haven't really learned that yet so I'll not even try that =D

@Jibran: Thanks for the help :)

@StuXYZ: you just lost me completely there :-/ btw I'm in America...

Be a part of the DaniWeb community

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