how can i make a program that inputs month and year, and then output the days of the

Reply

Join Date: Oct 2009
Posts: 21
Reputation: needhelpe is an unknown quantity at this point 
Solved Threads: 0
needhelpe needhelpe is offline Offline
Newbie Poster

how can i make a program that inputs month and year, and then output the days of the

 
0
  #1
Oct 16th, 2009
how can I make a program that inputs the month and year. and then should output the days of the month.
-january, march, may, july, august, october, and dicember have 31 days.
-april, june, september, and november have 30 days.
-february has 28 days in non-leap years and 29 in leap years.

please I need the code...
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,362
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning
 
-7
  #2
Oct 16th, 2009
Take it in small steps. First write a program that just lets you enter the year. Get that working then add more that lets you enter the month and day of month. If you enter the month as a number you can then create a switch statement that calculates the number of days in the month, as you have already posted.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 1,859
Reputation: twomers has a spectacular aura about twomers has a spectacular aura about twomers has a spectacular aura about 
Solved Threads: 55
twomers's Avatar
twomers twomers is offline Offline
Posting Virtuoso
 
0
  #3
Oct 16th, 2009
I doubt you'll get any code for free here. So here's an outline of how you might go about it.
Grab the input from the user and compare strcmp() it against references, i.e. "January", etc (might want to consider how you'd work with upper and lower case letters).
Then grab the year and see if it's a leap year (only necessary if the month is Feb though.

Have a go at trying this and get back to us with problems.
I blag!?
"Mr Kitty, you have to live in the attic now. Here, write a diary."
I am the Walrus!
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 76
Reputation: Gaiety is an unknown quantity at this point 
Solved Threads: 2
Gaiety's Avatar
Gaiety Gaiety is offline Offline
Junior Poster in Training
 
0
  #4
Oct 16th, 2009
start the main function

declare two int variables

int year, month;
read the year and month values
just a scanf statement with to arguments .

now starts the procedure:

first check whether given year is a leap year or not
a leap year comes for every four years.(so it is divisible by four)

a century year is a leap year if its divisible by 400.
that means any year divisible only by 100 is not a leap year, if not divisible by 400.

so club all these conditions in if ( year % 4 ==0 || !( year %100==0)&&year %400 ==0)

so the year is a leap year
take a two dimentional array
int years[2][12];

and assign the value starting form january,
years[0][0] =31, years[0][1]=28 (non leap) till years[0][11]=31 december
january , years[1][0] =31, years[1][1]=29 (leap) till years[1][11]=31 december

from the pogram find out what is the month

so chose the appropriate index for the year and month

you should get it with above hint!
Minds are like parachutes - they only work when they are open
Gaiety
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 28
Reputation: OSiRiSsk is an unknown quantity at this point 
Solved Threads: 0
OSiRiSsk OSiRiSsk is offline Offline
Light Poster
 
0
  #5
Oct 18th, 2009
ive been learning this on my math lesson, so if you want i can give you the math algorythm for this problem, and then you should be able to code that without any problem
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,362
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning
 
-7
  #6
Oct 18th, 2009
Originally Posted by OSiRiSsk View Post
ive been learning this on my math lesson, so if you want i can give you the math algorythm for this problem, and then you should be able to code that without any problem
There is no math involved.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 28
Reputation: OSiRiSsk is an unknown quantity at this point 
Solved Threads: 0
OSiRiSsk OSiRiSsk is offline Offline
Light Poster
 
0
  #7
Oct 18th, 2009
Originally Posted by Ancient Dragon View Post
There is no math involved.
you can look at this problem from math side, as we did in my class
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC