16.0k views
0 votes
Write a program that inputs an integer denoting a month (1 for January, 2 for February, ... , 12 for December), and outputs how many days are in that month. Assume no leap years. For example, if the input is 2, the output is 28. If the input is 11, the output is 30.[ There are a variety of ways to do this...One approach is to use 12 separate if-then statements. Another approach uses just 3 if-then statements and the logical OR operator (which is ||). ]

User AnD
by
7.1k points

1 Answer

4 votes

Answer:

// program in C++.

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

// variable

int inp_month;

cout<<"Enter month:";

// read month

cin>>inp_month;

// if month is february

if(inp_month==2)

cout<<"Number of days in month:28"<<endl;

// if month is 4 or 6 or 9 or 11

else if(inp_month==4

Step-by-step explanation:

Read month from user and assign it to variable "inp_month".If month is 2 then there is 28 days in the month.If input month is 4 or 6 or 9 or 11 then there is 30 days in the month.For other month there will be 31 days in month.We assume there is no leap year.

Output:

Enter month:4

Number of days in month:30

User ZOXEXIVO
by
7.4k points