Switch with no break

posted Jan 28, 2013, 1:53 AM by Karwan Jacksi   [ updated Jan 28, 2013, 1:53 AM ]
#include <iostream>

using namespace std;

void main()
{
// This program demonstrates how a switch statement
// works if there are no break statements.
char choice;
cout << "Enter A, B, or C: ";
cin >> choice;
// The following switch statement is missing its break statements!
switch (choice)
 {
case 'A':cout << "You entered A.\n";
case 'B':cout << "You entered B.\n";
case 'C':cout << "You entered C.\n";
default :cout << "You did not enter A, B, or C!\n";
 }

 system("pause");
}

Comments