Gargit

Conditional Statements Exercises Part 7

Jul 30th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. void main()
  4. {
  5.     int month = 0;
  6.     int days = 0;
  7.  
  8.     std::cout << "Enter number of month: ";
  9.     std::cin >> month;
  10.  
  11.     switch (month)
  12.     {
  13.         case 9:
  14.         case 4:
  15.         case 6:
  16.         case 11:
  17.             days = 30;
  18.             break;
  19.         case 1:
  20.         case 3:
  21.         case 5:
  22.         case 7:
  23.         case 8:
  24.         case 10:
  25.         case 12:
  26.             days = 31;
  27.             break;
  28.         case 2:
  29.             days = 28;
  30.             break;
  31.         default:
  32.             std::cout << "Not a valid month number!" << std::endl;
  33.             break;
  34.     }
  35.  
  36.     if (days != 0)
  37.     {
  38.         std::cout << "The days in month number " << month << " are: " << days << std::endl;
  39.     }
  40.  
  41.     system("pause");
  42. }
Advertisement
Add Comment
Please, Sign In to add comment