#include <iostream>
using namespace std;
int main(){
cout<<"What year are you in"<<endl;
int a(0);
cin>>a;
int b(a % 4);
cout<<"Enter an index for one of the 12 months of the year:"<< endl;
int month{0};
cin>>month;
switch(month){
case 1:
cout<<"January is 31 days";
break;
case 2:{
if(b=0){
cout<<"February is 29 days";}
break;}
case 3:{
if (b!=0){
cout<<"February is 28 days";}
break;
}
case 4:
cout<<"March is 31 days";
break;
case 5:
cout<<"April is 30 days";
break;
case 6:
cout<<"May is 31 days";
break;
case 7:
cout<<"June is 30 days";
break;
case 8:
cout<<"July is 31 days";
break;
case 9:
cout<<"August is 31 days";
break;
case 10:
cout<<"September is 30 days";
break;
case 11:
cout<<"October is 30 days";
break;
case 12:
cout<<"November is 30 days";
break;
case 13:
cout<<"December is 31 days";
break;
default:
cout<<"Not a valid index";
}
return 0;
}
Write a C program that takes in the index of a month (1 for January, 2 for February, ...etc.) and displays how many days there are in that month. Now modify the above code, this time accounting for leap years (i.e., when February is 29 days instead of 28).
I was trying to display to day of the months and i made it but when deciding february is 28 or 29 i'm stuck and i don't know what to do here please help me.I don't know if im using modulus wrong or maybe paranthesis. How do i make this work?