Answer to Question #249277 in C++ for Urooj

Question #249277

You are a freelance calendar maker. Unfortunately, like me, you are useless are remembering how many days there are in each month of the year.


Write a program that uses a switch statement to tell a user how many days there are in a month.


Your cases should test a number corresponding to the months (e.g. 1 = January, 12 = December), and true cases should print out how many days there are in a month.




1
Expert's answer
2021-10-10T09:09:26-0400


#include<iostream>
using namespace std;






int main(){
	int days[12] = {31,28,31,30,31,30, 31,31, 30, 31, 30, 31}; 
	cout<<"Enter month (e.g. 1 for January, 12 for December)\n";
	int month;
	cin>>month;
	
	switch(month){
		case 1: cout<<" Number of days:  " <<days[0]<<endl; break;
		case 2: cout<<" Number of days:  " <<days[1]<<endl; break;
		case 3: cout<<" Number of days:  " <<days[2]<<endl; break;
		case 4: cout<<" Number of days:  " <<days[3]<<endl; break;
		case 5: cout<<" Number of days:  " <<days[4]<<endl; break;
		case 6: cout<<" Number of days:  " <<days[5]<<endl; break;
		case 7: cout<<" Number of days:  " <<days[6]<<endl; break;
		case 8: cout<<" Number of days:  " <<days[7]<<endl; break;
		case 9: cout<<" Number of days:  " <<days[8]<<endl; break;
		case 10: cout<<" Number of days:  " <<days[9]<<endl; break;
		case 11: cout<<" Number of days:  " <<days[10]<<endl; break;
		case 12: cout<<" Number of days:  " <<days[11]<<endl; break;
	}
	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS