| | |
how can i make a program that inputs month and year, and then output the days of the
![]() |
•
•
Join Date: Oct 2009
Posts: 21
Reputation:
Solved Threads: 0
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...
-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...
-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.
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.
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.
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!
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
Gaiety
-7
#6 Oct 18th, 2009
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.
![]() |
Similar Threads
- ask the user for a year and a month in numbers. Out the number of days in a month. (Java)
- Make a VB Program run in the background? (VB.NET)
- HELP me make a program pleasssee!!!!!! (C++)
- Tips to make your program more efficient (C++)
- trying to make a program to say the change due back after a purchase is made (C++)
- day month year help (C++)
- How to make my program detecct when the computer is going to LOGOFF or SHUTDOWN (C)
- how can i make the program depend on time (C)
Other Threads in the C Forum
- Previous Thread: how to scan arrow keys from keyboard in c?
- Next Thread: binary search
| Thread Tools | Search this Thread |
#include * adobe ansi array asterisks binarysearch centimeter changingto char character cm convert copyimagefile cprogramme creafecopyofanytypeoffileinc database dynamic execv feet fgets file floatingpointvalidation fork function getlogicaldrivestrin givemetehcodez global grade gtkwinlinux hacking histogram ide inches include incrementoperators infiniteloop input interest intmain() iso kernel keyboard kilometer license linked linkedlist linux list locate looping lowest match matrix meter microsoft number oddnumber opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer posix power probleminc process program programming radix recursion recv recvblocked research reversing segmentationfault sequential single socket socketprograming socketprogramming standard strchr string suggestions systemcall test threads turboc unix urboc user variable voidmain() wab whythiscodecausesegmentationfault windowsapi






