Please comment all steps as I\'m new to programming and need the influence. This
ID: 3630714 • Letter: P
Question
Please comment all steps as I'm new to programming and need the influence. This program has to be written in C and be able to be compiled on emacs. Thank youWrite a program weekday.c that prompts the user for a date (entered as month/day) this year, and outputs the day of the week the date falls on. Use the fact that this year (2011), January 1st was a Saturday and that January, March, May, July, August, October, and December have 31 days, April, June, September, and November have 30 days, and February this year had 28 days. Note: Do not specify in the program the rst day of each month (e.g., that February 1st will fall on a Tuesday, etc.). Instead, use one switch statement to calculate the number of days till the date
entered, and another switch statement to print the day of the week.
Here is a sample run:
(~)$ a.out
Enter today's date: 03/21
Happy Monday!
(~)$ a.out
Enter today's date: 5/14
Happy Saturday!
(~)$ a.out
Enter today's date: 11/24
Happy Thursday!
(~)$
This is what I have come up with so far. I'm not sure how to link thw switch to everything??
// program to return the day of the week given the date (jan 1st Sat.)
#include <stdio.h>
int main()
{
int value1 = month, value2 = day
int date = month/day
int year = 365
int month = 12
for(jan1sat = 1, month =>1 && month =<12 || day =>1 && day =<31, ++jan1sat)
{
printf("Enter today's date: ");
scanf("%d/%d, &jan1sat);
switch(date)
{
case 7:
printf("Happy Sunday! ");
break;
case 6:
printf("Happy Monday! ");
break;
case 5:
printf("Happy Tuesday! ");
break;
case 4:
printf("Happy Wednesday! ");
break;
case 3:
printf("Happy Thursday! ")
break;
case 2:
printf("Happy Friday! ")
break;
case 1:
printf("Happy Saturday! ");
break;
return 0;
}
}
}
Explanation / Answer
please rate - thanks
// program to return the day of the week given the date (jan 1st Sat.)
#include <stdio.h>
int main()
{char input[6];
int i,month=0,day=0;
printf("Enter today's date:(m/d) ");
scanf("%s", &input);
for(i=0;input[i]!='/';i++)
month=month*10+(input[i]-'0');
i++;
for(;input[i]!='';i++)
day=day*10+(input[i]-'0');
day--;
for(i=1;i<month;i++)
{switch(i)
{case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: day+=31;
break;
case 2: day+=28;
break;
default: day+=30;
break;
}
}
day%=7;
switch(day)
{
case 1:
printf("Happy Sunday! ");
break;
case 2:
printf("Happy Monday! ");
break;
case 3:
printf("Happy Tuesday! ");
break;
case 4:
printf("Happy Wednesday! ");
break;
case 5:
printf("Happy Thursday! ");
break;
case 6:
printf("Happy Friday! ");
break;
case 0:
printf("Happy Saturday! ");
break;
}
getch();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.