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
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.
Write a program in C++ coding that asks the user to input an integer between 25...
Write a program in C++ coding that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2...
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....
(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 a program that asks the user to input an integer between 25 and 50, inclusive....
Write a program that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2 relational expressions. You...
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1....
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January - December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs to adjust the...
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...
Write a C++ program that sets the maximum speed limit as a constant integer to be...
Write a C++ program that sets the maximum speed limit as a constant integer to be 120 Km/Hour. The program should read from the user an integer value representing the speed of a car. Use a nested if else to display a message based on the input speed: Speed < 10                      display      “Invalid speed” 10 <= Speed <= 120       display      “Speed is within limit” Speed > 120                    display      “Speed limit exceeded” At the end the program should display a message...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...