Write C++ program to print day of week name 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 weeknumber;
  8.  
  9. //Reading week no from user
  10. cout<<"Enter week number(1-7): ";
  11. cin>>weeknumber;
  12.  
  13. switch(weeknumber)
  14. {
  15. case 1: cout<<"Monday";
  16. break;
  17. case 2: cout<<"Tuesday";
  18. break;
  19. case 3: cout<<"Wednesday";
  20. break;
  21. case 4: cout<<"Thursday";
  22. break;
  23. case 5: cout<<"Friday";
  24. break;
  25. case 6: cout<<"Saturday";
  26. break;
  27. case 7: cout<<"Sunday";
  28. break;
  29. default: cout<<"Invalid input! Please enter week no. between 1-7.";
  30. }
  31.  
  32. return 0;
  33.  
  34. }
  35.  

Result

C++ language techstudy.org

     





Related Topics




Popular Posts