The switch Statement

There is another way of handling the semantics of an if statement. Consider the following :

// file : sw.C
#include <iostream.h>
int main()
{
  char mdb;

  cout << "(M)other's day or (F)ather's day or (B)irthday? ";
  cin >> mdb;

  switch(mdb)
  {
    case 'M': case 'm':
      cout << "Hello Mom - Happy Mother's Day!\n";
      break;
    case 'F': case 'f':
      cout << "Hello Dad - Happy Father's Day!\n";
      break;
    case 'B': case 'b':
      cout << "Happy Birthday!\n";
      break;
  }

  return 0;
}

The above program is semantically equivalent to the following :

// file : sw_as_if.C
#include <iostream.h>
int main()
{
  char mdb;

  cout << "(M)other's day or (F)ather's day or (B)irthday? ";
  cin >> mdb;

  if ((mdb == 'M') || (mdb == 'm'))
    cout << "Hello Mom - Happy Mother's Day!\n";
  else if ((mdb == 'F') || (mdb == 'f'))
    cout << "Hello Dad - Happy Father's Day!\n";
  else if ((mdb == 'B') || (mdb == 'b'))
    cout << "Happy Birthday!\n";

  return 0;
}