November 28th, 2012, 11:46 AM
Help Writing my first program!
Hello! This is one of the second programs I have been assigned to do, but as a beginner I am a little bit lost on where to start and how to go about creating this program.
The program I have to write is to:
Finding the day of the week corresponding to a specific date.
-It has to read a date
-Compute the corresponding day of the week N using the formula given below
-Output the result (with the day of the week as a word not a number)
I have to use Zeller's congruence equation
h = ( q + (13*(m+1))/5 + K + K/4 + J/4 + 5*J)
- J is the number of the century [i.e. the year / 100],
- K the year within the century [i.e. the year % 100],
- m the month,
- q the day of the month,
Note that in this formula:
- the month indices are: March: 3, April: 4,...but with January being 13 and February being 14.
- January and February are counted as part of the previous year
h is a representation of the date as number of days since a starting time. It can then be converted into a day of the week using: N = h%7
i.e. the remainder of the division of h by 7. N is the day of the week, with 0 being Saturday, 1 being Sunday,...
As a beginner I am kind of lost. Could anyone give me any tips on how to go about writing this program? Thank You!
November 28th, 2012, 11:58 AM
I think you start with a date being supplied. This will probably be a user input (?) and we'll need to make some assumption about the format. For now, let's say that the date comes in American-style: mm/dd/yyyy.
First split the user input string on "/" and assign month,day,year variables to the elements (after converting the strings to numbers):
Now you want to get the variables in your designated algorithm from those 3 variables:
What more do you need?
if mnth<3: mnth+=12