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

#C. Write a program that accepts any number of homework scores ranging in value from 0...
#C. Write a program that accepts any number of homework scores ranging in value from 0 through 10. Prompt the user for a new score if they enter a value outside of the specified range. Prompt the user for a new value if they enter an alphabetic character. Store the values in an array. Calculate the average excluding the lowest and highest scores. Display the average as well as the highest and lowest scores that were discarded.
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
Write a C++ Program. Include the Homework header. Then prompt the user for a temperature that...
Write a C++ Program. Include the Homework header. Then prompt the user for a temperature that is in Fahrenheit for some water. Input the temperature (either an int or a double).   then output one of three statements: if the temperature is below 32 degrees or below tell them it is ice. For example if they input 22 then the output would be: At a temperature of 22 degrees the water would take the form of ice. if the temperature is...
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...
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 python program that will ask the user to enter any number of days. The...
Write a python program that will ask the user to enter any number of days. The program reads the number of days from the user, and returns how many years, months, and days are there in the given number of days. Your program should prompt the user to: Enter the number of days : 1152 The user types number of days (1152 above, for example) and hit enter key. The program then will print: 3 years 1 months 27 days...
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; }
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 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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT