Write an program to implement months to days like -- users can input months number and program can show the number of days
With Switch case
No C program
Answers
#include<iostream.h>
#include<conio.h>
void main()
{
int monthno,ch;
cout<<"Month to days calculation";
cout<<"Enter the month's number";
cin>>monthno;
switch(ch)
{
case 1:
if(monthno=1)
{
cout<<"January=31days";
}
break;
case 2:
if(monthno=2)
{
cout<<"February=28days";
}
break;
case 3:
if (monthno=3)
{
cout<<"March=31days";
}
break;
case 4:
if(monthno=4)
{
cout<<"April=30days";
}
break;
case 5:
if(monthno=5)
{
cout<<"May=31days";
}
break;
case 6:
if(monthno=6)
{
cout<<"June=30days";
}
break;
case 7:
if(monthno=7)
{
cout<<"July=31days";
}
break;
case 8:
if(monthno=8)
{
cout<<August=31days";
}
break;
case 9:
if(monthno=9)
{
cout<<September=30days";
}
break;
case 10:
if (monthno=10)
{
cout<<"October=31days";
break;
case 11:
if (monthno=11)
{
cout<<"November=30days";
}
break;
case 12:
if(monthno=12)
{
cout<<"December=31days";
}
break;
default:
cout<<"Enter the right choice";
break;
getch();
}
Answer:
Program in C++
==============
#include <iostream>
using namespace std;
void main(){
int no_of_month, no_of_days;
int leap_test;
//Birupaksha Nath
printf("Enter the no. of the month:\t");
scanf("%d",&no_of_month);
printf("\n\n");
switch(no_of_month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
no_of_days=31;
break;
case 4:
case 6:
case 9:
case 11:
no_of_days=30;
break;
case 2:
printf("Is it leap year?\n\tPress 1 for YES\n\tPress 0 for NO\n");
scanf("%d",&leap_test);
if(leap_test==1){
no_of_days=29;
}
else{
no_of_days=28;
}
break;
default:
no_of_days=0;
break;
}
printf("\nThe month has %d days.\n\n\n",no_of_days);
}
Explanation: