Question

Write a program (C language) that will read the number of a month and will print...

Write a program (C language) that will read the number of a month and will print the number of days in the month. Ignore leap years. Use 28 days for February.

Have the program runs in a continuous loop, allowing the user to enter a month number, see that number of days, and repeat. Use month number = 0 to exit the loop and the program.

Program must meet the following criteria:

1.Your name and the name of the program embedded in a comment, and displayed on execution.

2.Ask the user to enter a month number.

3.Use if or if-else statements to decide how many days are in the month entered. Set a “day” equal to the number of days in the month ( if entered 2 (February) for the month, then day=28).

4.Include if or if-else statement(s) (decision) to make sure the user has entered a valid value for the month, between 1 and 12. If entry is invalid, ex..13, then display a polite error message, and no number-of-days display.

5.Send a message to the user with the month number and the number of days in that month (ex.“Your month was 2 and it has 28 days.”).

6. Do not use 12 or 13 if statements. Use 5 MAXIMUM. You can use one if statement for all of the months that have 31 days; another for all of the months that have 30 days; and one for Feb.

Homework Answers

Answer #1

#include<stdio.h> // header file for standard input and output

int main()

{

int day; //define the variable day as integer type

printf("Name \n Program to display number of days in a month");

//Replace the name with your name. To print the name and program name

while(1) //continuous loop

{

printf("\n Enter a month number");

scanf("%d",&day);

if(day==1||day==3||day==5||day==7||day==8||day==10||day==12) //Logical OR operator is used to check either cases

printf("Your month was %d and it has 31 days",day);

else if(day==4||day==6||day==9||day==11)

printf("Your month was %d and it has 30 days",day);

else if(day==2)

printf("Your month was %d and it has 28 days",day);

else if(day>12) //If entered number is greater than 12

printf("Error message: Please enter a valid number from 1 to 12");

else if(day==0)

break; // exit the loop

}

return 0;

}

//after entering the month number please press enter to receive the ouput

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Leap Year The month of February normally has 28 days. But if it is a leap...
Leap Year The month of February normally has 28 days. But if it is a leap year, February has 29 days. Write a program that asks the user to enter a year. The program should then display the number of days in February that year. Use the following criteria to identify leap years: Determine whether the year is divisible by 100. If it is, then it is a leap year if and if only it is also divisible by 400....
Write a program that asks the user to enter the number of days and then converts...
Write a program that asks the user to enter the number of days and then converts that value to weeks and days. For example, it would convert 18 days to 2 weeks, 4 days. Display results in the following format: 18 days are 2 weeks, 4 days. Use a while loop to allow the user to repeatedly enter day values; terminate the loop when the user enters a nonpositive value, such as 0 or -20.
(Use C++ language) Create a program, named threeTypesLoops.cpp, that does the following; 1. Uses a For...
(Use C++ language) Create a program, named threeTypesLoops.cpp, that does the following; 1. Uses a For Loop that asks for a number between 1 and 10; Will double the number each time through the loop and display the answer. Will run five times, so the number will have been doubled five times, and the answer displayed five times. After the loop, display a message saying 'It's done!'. 2. Uses a While Loop; Ask the user to input a friend's name....
Write the C++ language statements to ask a user to enter a number within the range...
Write the C++ language statements to ask a user to enter a number within the range of 0 to 100 (0 and 100 are valid inputs). When the value is not valid, you should prompt the user to enter another value. (The user may enter many invalid numbers, so you must use loop). Only after the user enters a valid number should you display the message “Good” and the value of the number.
In C programming language please. -Construct a program that will make use of user defined functions,...
In C programming language please. -Construct a program that will make use of user defined functions, the do/while loop, the for loop and selection. -Using a do/while loop, your program will ask/prompt the user to enter in a positive value representing the number of values they wish to have processed by the program or a value to quit/exit. -If the user enters in a 0 or negative number the program should exit with a message to the user indicating they...
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a...
**JAVA LANGUAGE** Write a program that models an employee. An employee has an employee number, a name, an address, and a hire date. A name consists of a first name and a last name. An address consists of a street, a city, a state (2 characters), and a 5-digit zip code. A date consists of an integer month, day and year. All fields are required to be non-blank. The Date fields should be reasonably valid values (ex. month 1-12, day...
C++ The problem is as below: The Greatest and Least of These Write a program with...
C++ The problem is as below: The Greatest and Least of These Write a program with a loop that lets the user enter a series of integers. The user should enter -99 to signal the end of the series. After all the numbers have been entered, the program should display the largest and smallest numbers entered.
Days of the week Write a program that asks the user for a number in the...
Days of the week Write a program that asks the user for a number in the range of 1 through 7. The program should display the corresponding day of the week, where 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, and 7 = Sunday. The program should display an error message if the user enters a number that is outside of the range of 1 though 7.
Write a C program to ask the user 3 number and display in the greater value...
Write a C program to ask the user 3 number and display in the greater value from it. Only use compound condition in if-Else statements.
Write a program that asks the user for a number in the range 1 through 12....
Write a program that asks the user for a number in the range 1 through 12. The program should display the corresponding month of the year, where 1 = January, 2 = February, 3 = March, 4 = April, 5 = May, 6 = June, 7 = July, 8 = August, 9 = September, 10 = October, 11 = November, and 12 = December. The program should display an error message if the user enters a number that is outside...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT