Write C++ program to print number of days in a month using switch case


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Introduction

I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.


  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int monthnumber;
  8.  
  9. //Reading a month number from user
  10.  
  11. cout<<"Enter month number(1-12): ";
  12. cin>>monthnumber;
  13.  
  14. switch(monthnumber)
  15. {
  16. case 1: cout<<"31 days";
  17. break;
  18. case 2: cout<<"28 or 29 days";
  19. break;
  20. case 3: cout<<"31 days";
  21. break;
  22. case 4: cout<<"30 days";
  23. break;
  24. case 5: cout<<"31 days";
  25. break;
  26. case 6: cout<<"30 days";
  27. break;
  28. case 7: cout<<"31 days";
  29. break;
  30. case 8: cout<<"31 days";
  31. break;
  32. case 9: cout<<"30 days";
  33. break;
  34. case 10: cout<<"31 days";
  35. break;
  36. case 11: cout<<"30 days";
  37. break;
  38. case 12: cout<<"31 days";
  39. break;
  40. default: cout<<"Invalid input!!! enter month number between 1-12";
  41.  
  42. }
  43. return 0;
  44.  
  45. }
  46.  

Result

C++ language techstudy.org

     





Related Topics




Popular Posts