I used the code below from one I found online. The instructions are to write a program that computes the day of the week for any date entered by the user by using Zeller's congruence. The user is prompted to enter a month, date, and year . The program will then display the day of the week for that date.
these are the following dates that i should be able to run in order to check that the program is good to go. :
5 17 2008 (should be 0-sat)
10 5 2008 (should be 1-sun)
9 15 2008 (should be 2-mon)
8 5 2008 (should be 3 tue)
9 13 2006 (should be 4-wed)
1 1 2009 (should be 5 Thurs) must be typed in as 13 1 2008
2 6 2009 (should be 6-fri) must be typed in as 14 6 2008
1 10 2000 (should be 2- mon) must be typed in as 13 10 1999
I am new to c++ and am having a hard time figuring out what I need to do to correct it.
and is there a way to a program without the if and/or switch statement , so it wont print the actual word for the day of the week , i.e saturday, monday, etc,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <stdio.h>
#include <math.h>
int main()
{
int h,q,m,k,j,day,month,year;
printf("Enter the date (dd/mm/yyyy)\n");
scanf("%i/%i/%i",&day,&month,&year);
if(month == 1)
{
month = 13;
year--;
}
if (month == 2)
{
month = 14;
year--;
}
q = day;
m = month;
k = year % 100;
j = year / 100;
h = q + 13*(m+1)/5 + k + k/4 + j/4 + 5*j;
h = h % 7;
switch(h)
{
case 0 : printf("Saturday. \n"); break;
case 1 : printf("Sunday. \n"); break;
case 2 : printf("Monday. \n"); break;
case 3 : printf("Tuesday. \n"); break;
case 4 : printf("Wednesday. \n"); break;
case 5 : printf("Thursday. \n"); break;
case 6 : printf("Friday. \n"); break;
}
return 0;
}
|