In: Computer Science
Write a program in C
A teacher will assign homework and give the number of days for
the students to work on. The student is responsible for calculating
the due date. The teacher does not collect homework on Friday or
weekend. Write a C program that let the user enter today’s day of
the week (0 for Sunday, 1 for Monday, etc.) and the number of days
to allow the students to do the work, which may be several weeks.
Calculate and display the day of the week on which the work would
be due. If that day Friday,
Saturday, or Sunday– add enough days to the number of days to reach
the following Monday. Print the day of the week the work is due and
the corrected value of the number of the days.
1. If the entered day for today is not in the range of 0 to 6,
display an error message and abort the program.
2. Display the corrected value of the number of days and the day of
the week the work is due. For example, if today is Thursday, and
the number of days is 8, then the due date falls on Friday, then 3
days will be added to reach the following Monday. So the corrected
value of the number of days is 11.
Example input/output:
Enter today’s day of the week: 6
Enter the number of days for doing the work: 15
Output: The due date is Monday. The number of days until due date
is 16.
#include <stdio.h> int main() { char *days[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; int day; int numDays; int count = 0; printf("Enter today’s day of the week: "); scanf("%d", &day); if(day < 0 || day >= 7) { printf("invalid day entered."); return 1; } printf("Enter the number of days for doing the work: "); scanf("%d", &numDays); while(numDays-- != 0) { day = (day + 1) % 7; count++; } while(day == 0 || day >= 5) { day++; count++; } printf("the due date is on %s. The number of days until due date is %d.\n", days[day], count); return 0; }
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.