Question

In: Computer Science

Write a program in C A teacher will assign homework and give the number of days...

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.

Solutions

Expert Solution

#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.


Related Solutions

Write a program that accepts a number of minutes and converts it to days and hours....
Write a program that accepts a number of minutes and converts it to days and hours. For example, 6000 minutes represents 4 days and 4 hours. Be sure to provide proper exception handling for non-numeric values and for negative values. Save the file as  MinuteConversionWithExceptionHandling.java
in basic c++ program please!! Write a word search and word count program. Assign the following...
in basic c++ program please!! Write a word search and word count program. Assign the following text to a string constant. For God so loved the world that he gave his one and only Son, that whoever believes in him shall not perish but have eternal life. For God did not send his Son into the world to condemn the world, but to save the world through him.Whoever believes in him is not condemned, but whoever does not believe stands...
In C++ Please, using only the libraries given in this homework prompt, Write a program that...
In C++ Please, using only the libraries given in this homework prompt, Write a program that (1) prompts for two integers, (2) prints out their sum, (3) prints out the first divided by the second, and (4) prints out the natural log of the first number raised to the power of the second number. #include <iostream> #include <iomanip> using namespace std; int main() { <your answer goes here> return 0; }
Use Java (Find the number of days in a month) Write a program that prompts the...
Use Java (Find the number of days in a month) Write a program that prompts the user to enter the month and year and displays the number of days in the month. For example, If the user entered month 2 and year 2012, the program should display that February 2012 has 29 days. If the user entered month 3 and year 2015, the program should display that March 2015 has 31 days. Sample Run 1 Enter a month in the...
write a Java program Write a program to assign a letter grade according to the following...
write a Java program Write a program to assign a letter grade according to the following scheme: A: total score >= 90 B: 80 <= total score < 90 C: 70 <= total score < 80 D: 60 <= total score < 70 F: total score < 60 Output - the student's total score (float, 2 decimals) and letter grade Testing - test your program with the following input data: test1 = 95; test2 = 80; final = 90; assignments...
C++ Write a program that asks a teacher to input a student’s first name, last name,...
C++ Write a program that asks a teacher to input a student’s first name, last name, and four test scores. The program should find the average of the four test scores and should then write the following information to a file named “students.txt” last_name first_name average A student's first name of “XX” should be used as a sentinel value and no numeric grades less than 0 or greater than 100 should be accepted.  The program should then read the information in...
Program in C++ **********Write a program to compute the number of collisions required in a long...
Program in C++ **********Write a program to compute the number of collisions required in a long random sequence of insertions using linear probing, quadratic probing and double hashing. For simplicity, only integers will be hashed and the hash function h(x) = x % D where D is the size of the table (fixed size of 1001). The simulation should continue until the quadratic hashing fails.*********
could you please assign this homework to this person if possible: Dumpydnp Write a 200- to...
could you please assign this homework to this person if possible: Dumpydnp Write a 200- to 400-word essay about the most important thing you learned while watching "Freedom of Speech."" Please answer based on the video-thank you Please watch the video- do not copy and paste from internet-thank you link: https://www.youtube.com/watch?v=Zeeq0qaEaLw&list=PL8dPuuaLjXtOfse2ncvffeelTrqvhrz8H&index=25 or typing in youtube: Freedom of Speech: Crash Course Government and Politics #25
could you please assign this homework to this person if possible: Dumpydnp Write a 200- to...
could you please assign this homework to this person if possible: Dumpydnp Write a 200- to 400-word essay about the most important thing you learned while watching "Freedom of the Press." please answer based on the video- short video ​do not copy and paste from internet -thank you watch this video by typing in youtube: Freedom of the Press: Crash Course Government and Politics #26 or link :https://www.youtube.com/watch?v=Vtpd0EbaFoQ&list=PL8dPuuaLjXtOfse2ncvffeelTrqvhrz8H&index=26
Write a C++ program that inputs two simplified poker hands (as defined in homework #5) and...
Write a C++ program that inputs two simplified poker hands (as defined in homework #5) and determines which (if either) of the hands is the winner, according to the following rules: • If the two hands have different types (3-of-kind, straight, pair, high-card), the hand with the better type (i.e., appears earlier in this list) wins. • If they have the same type, the higher significant card wins. • If the hands have the same type and significant card, there...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT